ajax--front-back and back-desk interaction

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.