Note: Ajax determines whether the async parameter is asynchronous or synchronous, false synchronous, true async;
The asynchronous execution order is to perform the following actions before executing the success code;
Synchronization is to execute the success code first, and then execute the subsequent code;
Verify: Is the amount of data in sync too large to be stuck? For example, when searching large amounts of data from the background, does the page get stuck?
1, ( asynchronous ) method invocation, subsequent code does not need to wait for its execution result
Backstage <c#>:
Using System.Web.Script.Services;
[WebMethod]
public static string Getstr (String str1, String str2)
{
return str1 + str2;
}
Front desk <jquery>:
function Test (STRMSG1,STRMSG2)
{
$.ajax ({
Type: "Post",
URL: "Demo.aspx/getstr",
Async:true,
method to write the parameters must be right, and background consistent, case-sensitive, not an array, etc., str1 as the name of the formal parameter, str2 the name of the second parameter
Data: "{' str1 ': '" +strmsg1+ "', ' str2 ': '" +strmsg2+ "'}",
ContentType: "Application/json; Charset=utf-8 ",
DataType: "JSON",
Success:function (data) {
The returned data gets content with DATA.D
alert (DATA.D);
},
Error:function (Err) {
alert (ERR);
}
});
Hide Load Animations
$ ("#pageloading"). Hide ();
}
2, ( synchronous ) method invocation, can be used to get the return value is to execute the following code premise
Backstage <c#>:
Using System.Web.Script.Services;
[WebMethod]
public static string Getstr (String str1, String str2)
{
return str1 + str2;
}
Front desk <jquery>:
function Test (STRMSG1,STRMSG2)
{
var str = "";
$.ajax ({
Type: "Post",
URL: "Demo.aspx/getstr",
Async:false,
method to write the parameters must be right, and background consistent, case-sensitive, not an array, etc., str1 as the name of the formal parameter, str2 the name of the second parameter
Data: "{' str1 ': '" +strmsg1+ "', ' str2 ': '" +strmsg2+ "'}",
ContentType: "Application/json; Charset=utf-8 ",
DataType: "JSON",
Success:function (data) {
The returned data gets content with DATA.D
str = DATA.D;
},
Error:function (Err) {
alert (ERR);
}
});
return str;
ajax--front-back and back-desk interaction