Note: Ajax usesAsync ParametersIt is determined whether it is asynchronous or synchronous, false synchronous, and true asynchronous;
The asynchronous execution order is to first execute the subsequent actions and then execute the code in success;
Synchronization is to first execute the code in success and then execute the subsequent code;
Verification: will the data volume during synchronization be choppy? For example, is the page stuck when a large amount of data is searched from the background?
1 ,(Asynchronous) Method call. Subsequent Code does not need to wait for its execution results.
Background <C #>:
Using system. Web. Script. Services;
[Webmethod]
Public static string getstr (string str1, string str2)
{
Return str1 + str2;
}
Foreground <jquery>:
Function Test (strmsg1, strmsg2)
{
$. Ajax ({
Type: "Post ",
URL: "demo. aspx/getstr ",
Async: True,
// Method parameters must be written in the same way as those in the background, case sensitive, cannot be an array, str1 is the name of the form parameter, and str2 is the name of the second form parameter.
Data: "{'str1': '" + strmsg1 + "', 'str2': '" + strmsg2 + "'}",
Contenttype: "application/JSON; charset = UTF-8 ",
Datatype: "JSON ",
Success: function (data ){
// Use data. D to obtain the returned data.
Alert (data. D );
},
Error: function (ERR ){
Alert (ERR );
}
});
// Hide an animation.
$ ("# Pageloading"). Hide ();
}
2 ,(Synchronization) Method call, which can be used to obtain the returned value is the prerequisite for executing subsequent code.
Background <C #>:
Using system. Web. Script. Services;
[Webmethod]
Public static string getstr (string str1, string str2)
{
Return str1 + str2;
}
Foreground <jquery>:
Function Test (strmsg1, strmsg2)
{
VaR STR = "";
$. Ajax ({
Type: "Post ",
URL: "demo. aspx/getstr ",
Async: false,
// Method parameters must be written in the same way as those in the background, case sensitive, cannot be an array, str1 is the name of the form parameter, and str2 is the name of the second form parameter.
Data: "{'str1': '" + strmsg1 + "', 'str2': '" + strmsg2 + "'}",
Contenttype: "application/JSON; charset = UTF-8 ",
Datatype: "JSON ",
Success: function (data ){
// Use data. D to obtain the returned data.
STR = data. D;
},
Error: function (ERR ){
Alert (ERR );
}
});
Return STR;