1.Ajax Library Mode
C # code:
[WebMethod]
public static DateTime GetCurrentTime (String str)
{
return datetime.now;
}
JS Code:
<form id= "Form1" runat= "Server" >
<script language=javascript type= "Text/javascript" >
function GetCurrentTime1 () {
Pagemethods.getcurrenttime (' NewEgg Ajax Training ', checkissuccess);
}
function checkissuccess (Result) {
alert (result);
}
</script>
<div>
<asp:scriptmanager id= "ScriptManager1" runat= "Server" enablepagemethods= "true" >
</asp:ScriptManager>
<input id= "Button1" type= "button" value= "client control calls the server-side method" onclick= "GetCurrentTime1 ()"/>
</div>
</form>
Description
C # methods must add "[WebMethod]"
The foreground page must use a reference server control
<asp:scriptmanager id= "ScriptManager1" runat= "Server" enablepagemethods= "true" >
</asp:ScriptManager>
Calling method: Pagemethods. Background method Name (parameter [, parameter ...], method name called after success);
Ajax Library
2. jquery method
C # code:
[WebMethod]
public static string ABC (string ABC)
{
return ABC;
}
JS Code:
$ (). Ready (
function () {
$ ("#AjaxDemo"). Click (function () {
$.ajax ({
Type: "POST",
URL: "Default.aspx/abc",
Data: "{' ABC ': ' Test '}",
ContentType: "Application/json; Charset=utf-8 ",
Success:function (msg) {alert (msg);}
})
})
}
)
Description: The jquery library file must be referenced.
3. There is also a sort of reference to the AJAX.dll file. Register the foreground method in the background. This one seems to be used more in. net2.0. Specifically not studied carefully.