Today you need to use the Ajax get method, encapsulated into its own custom function name, inside but found a problem, always will be the custom of the method inside the whole execution of the code to execute the GET, which led to a different step, which gives us programmers with great inconvenience,
Get when no synchronization code is used
Function name () {
ret = ' Y ';
$.get ("xx.php", function (data) {
ret = data;
});
return ret;
}
The resulting result is always not y and then it gets the things inside the GET request, which creates a different step, and you can use the following code
Set the synchronization global variables for Ajax
$.ajaxsetup ({
Async:false
});
This will be synchronized, but I tested it, and some of my code conflict, resulting in the full CPU, or can be another way
$.ajax ({
Type: "Get",
URL: "url",
Async:false,//Open Sync
Success:function (R) {
The code you're going to execute
}
});
Example
<%@ page language= "java" pageencoding= "Utf-8"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>JQuery</title>
<mce:script type= "Text/javascript" src= "/script/jquery-1.4.2.js" mce_src= "Script/jquery-1.4.2.js" ></MCE: Script>
<mce:script type= "Text/javascript" ><!--
/** Synchronous Ajax request, in a method body, the function of the method body relies on the AJAX response result * *
function loadsomething ()
{
var condition= "";
$.ajax ({
async:false;//using synchronized AJAX requests
Type: "POST",
URL: "some.php",
Data: "Name=john&location=boston",
Success:function (msg) {
condition=msg;
}
});
/**
* Deal with condition here
* If used asynchronously, perhaps the AJAX request does not respond to the client, but is dropped by the code below the Ajax
* So it could be a problem
*/
}
--></mce:script>
<body>
</body>