Jquery Ajax asynchronous cross-origin submission form instance Parsing

Source: Internet
Author: User

The result still does not work. The final solution is as follows:

1. Add async: false. That is, it is changed to synchronous. What does it mean? (According to my colleague, This is the webpage effect that will be executed only after Ajax has returned the value. In other words, the assignment in many Ajax calls does not work ). In this way, after Ajax assigns a value to the Bol, the following webpage special effect section will be executed. If it was just asynchronous, it was no longer time to assign values, and it was already returned.

Code
Copy the Code as follows:
Function getajaxreturn ()
{
VaR Bol = false;
$. Ajax ({
Type: "Post ",
Async: false,
Http://www.111cn.net/userexist.aspx ", URL: the URL of an action
Data: "username =" + vusername. value,
Success: function (MSG ){
If (MSG = "OK "){
Showtipex (vusername. ID, " <B> <font color =' # FFFF00 '> this user name can be used </font> </B> ", false)
// Return true;
BOL = true;
}
Else
{
Showtipex (vusername. ID, " <B> <font color =' # FFFF00 '> this user has been registered </font> </B> ", false );
Vusername. classname = "bigwrong ";
// Return false;
}
}
});
Return Bol;
}

2. pass in a function to solve this problem.

Code
Copy the Code as follows:
Function getajaxreturn (success_function, fail_function)
{
VaR Bol = false;
$. Ajax ({
Type: "Post ",
Http://www.111cn.net/userexist.aspx ",
Data: "username =" + vusername. value,
Success: function (MSG ){
If (MSG = "OK "){
Showtipex (vusername. ID, " <B> <font color =' # FFFF00 '> this user name can be used </font> </B> ", false)
Success_function (MSG );
}
Else
{
Showtipex (vusername. ID, " <B> <font color =' # FFFF00 '> this user has been registered </font> </B> ", false );
Vusername. classname = "bigwrong ";
Fail_function (MSG );
// Return false;
}
}
});
Function success_function (Info)
{
// Do What You Want do
Alert (Info );
}
Funciont fail_function (Info)
{
// Do What You Want do
Alert (Info );
}

 

Related Article

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.