(Original) also writes Ajax entry-1

Source: Internet
Author: User

The page calls JS, and JS accesses the WebService method to implement asynchronous data calling.

Create default. aspx and drag and drop the scriptmanager control to the page.

As follows:

<Asp: scriptmanager runat = "server" id = "script1" enablepagemethods = "true">
<Scripts>
<Asp: scriptreference Path = "~ /JS/JScript. js "/>
</Scripts>

<Services>
<Asp: servicereference Path = "~ /WebService. asmx "/>
</Services>
</ASP: scriptmanager>

<Input type = "button" value = "ajax say hello" id = "btngetajax" onclick = "Return sayhello ()"/>
<Span id = "result"/>

Create a JS file using the following method:

 

Function sayhello (){
WebService. helloworld (completeajax );
}

Function completeajax (result ){
Document. getelementbyid ("result"). innerhtml = result;
}

Create a new WebService. asmx file, which contains WebService. CS in app_code.

Declare in this class: using system. Web. Services;

Using system. Web. Script. Services;

 

[Scriptservice]
Public class WebService: system. Web. Services. WebService {

Public WebService (){

// Uncomment the following line if using designed components
// Initializecomponent ();
}

[Webmethod]
Public String helloworld (){
Return "Hello world-li ";
}
}

OK. Run it. This is a very simple example!

I hope I can help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.