Because of the unique advantages of Ajax, so that it in the current large number of Web sites have been widely used, the following describes how Ajax calls the background-defined functions, although relatively simple, but hope to bring some help for beginners, the code is as follows:
1. First we create a antzone.aspx page.
2. Create the following function in its CS file:
public static string MyTest (string A, string second)
{return return
First+second;
The 2.html code is as follows:
<form id= "MyForm" runat= "Server" >
<div>
<asp:button id= "BT" runat= "Server" text= "click Test"/>
</div>
The 3.javascript code is as follows:
$ (function () {
$ ("#bt"). Click (function () {
$.ajax ({
type: Post),
URL: "Antzone.aspx/mytest",
Data: "{' I ': ' Ant Tribe ', ' second ': ' Welcome you '}",
contentType: "Application/json;charset=utf-8",
dataType: "JSON",
success:function (data) {
//returned DATA.D get content
alert (DATA.D);
},
error:function (err) {
alert (err);
}
);
Disable submit return False for button;
The code above implements the functionality we need to invoke the function defined in the background. How to realize the definition of Ajax call background based on jquery first to introduce to you here, where there is no understanding of the place to welcome your message, thank you.