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/