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 );
}