1. Install ASP. NET ajax1.0. Click to install
2. Add reference in the web project: system. Web. Extensions (Version: 1.0.61025.0)
3. modify web. config and add the following sub-nodes to the <system. Web> node:
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
4. Add the following code to the related Aspx. cs. Note that the static method is used.
[WebMethod]
public static string AjaxTest(string str)
{
return "Hello " + str;
}
5. jquery call:
<SCRIPT type = "text/JavaScript">
Function ajaxtest (STR ){
$. Ajax ({
URL: "/default. aspx/ajaxtest ",
Type: "Post ",
Datatype: "JSON ",
Contenttype: "application/JSON ",
Data: "{'str': '" + STR + "'}",
Success: function (data ){
Alert (data );
},
Error: function (x, e ){
Alert (X. responsetext );
// Alert ("failed !! ");
}
});
}
</SCRIPT>