How does ajax call the method defined in the background?

Source: Internet
Author: User

How does ajax call the method defined in the background?

How does ajax call the method defined in the background:
Thanks to the unique advantages of ajax, it has been widely used in a large number of websites. The following describes how ajax calls the functions defined in the background, although relatively simple, however, the Code is as follows:
1. First, create an antzone. aspx page.
2. Create the following function in its cs file:

 

public static string mytest(string first, string second) {    return return first+second; }

 

2.html code:

<Form id = "myform" runat = "server"> <div> <asp: button ID = "bt" runat = "server" Text = "click to test"/> </div> </form>

3. The javascript code is as follows:

$ (Function () {$ ("# bt "). click (function () {$. ajax ({type: "Post", url: "antzone. aspx/mytest ", data:" {'first ': 'Ant tribe', 'second': 'Welcome '} ", contentType:" application/json; charset = UTF-8 ", dataType:" json ", success: function (data) {// data is returned. d. Obtain the content alert (data. d) ;}, error: function (err) {alert (err) ;}}); // return false when the disabled button is submitted ;});});

The above code implements the functions we need and can call the functions defined in the background.
The code is very simple. I will not introduce Russia much here. You can analyze it yourself or leave a comment with the post.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9045.

For more information, see: http://www.softwhy.com/jquery/

 

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.