Set variable value on success
This question already has an answer here:
Since you need this behavior in the unload event, you will have to make a synchronous call instead. However it may freeze the browser window/tab dependent on how long the call will take, but because you're effectively trying to prevent the user from closing the window...
Add async: false
to your JSON to make a synchronous call.
An example of jquery page:
var html = $.ajax({
url: "some.php",
async: false
}).responseText;
Source: http://api.jquery.com/jQuery.ajax/
The thing is that the request to Ajax call is asynchronous. So by the time you are checking you IsInitialized the call has not finished yet.
I suggest specifying your behaviour in the success function.
Basically having synchronous calls with ajax is if not impossible than really discouraged.
链接地址: http://www.djcxy.com/p/9482.html下一篇: 成功设置变量值