jQuery Ajax call - Set variable value on success [duplicate] jQuery Ajax call - Set variable value on success [duplicate] ajax ajax

jQuery Ajax call - Set variable value on success [duplicate]


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.