Hi all, I have to execute an AJAX request in a function and only exit this function when the request have been terminated. This is an example : function myFunction() { var result; try { $.ajax({ type: 'POST', url: 'myPage.php', ... success: function(data){ // do something with result }, error: function(){ // do something else with result } }); } catch(e) { alert(e); result = false; } return result; }
As I think you can understand, I want to "return result" be executed only when my success (or error) process have been terminated ... I tried to use async option but the result is the same, this is not waiting for the end of the AJAX function. I've find a solution but not very nice (an infinite "while" waiting for a variable toggle to true) ... I hope better ... Can I have some help please ?