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.

Leave a Comment