0

I noticed that when I call a function with ajax request, and update a file on the server on the same time, the call will never return, and I don't get 'error' message from ajax error function.
I must mention that I get the error alert on most cases. Here is my ajax call:

ajax_request = $.ajax({
        url: ajax_url+"/"+action, 
        data: params,
        type: 'post',                  
        async: false,
        dataType: 'jsonp',
        timeout: 6000,
        crossDomain: true,
     beforeSend: function() {
        //...
        loaderSearch.show();
    },
    complete: function(data) {                  
        //...   
    },
    success: function (data) {
        //...
    },error: function(){
         //...
         alert('error')
    }
Tariq
  • 2,853
  • 3
  • 22
  • 29
  • Remove `async: false` – Rory McCrossan Oct 15 '16 at 19:21
  • But I need this to be false, otherwise it will cause errors. How to set it to false and catch error on the same time? does timeout option help? – Tariq Oct 15 '16 at 19:27
  • You shouldn't use `async: false` at all. It's horrendous practice to use it as it blocks the UI thread while the request is active - that's why you get warnings in the console about it's use. If you structure your code correctly then you should get no errors. You haven't given enough information about how your code is structured for anyone to help you in this question. All I can do is guide you to [this question](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) for a guide on how to structure asynchronous code correctly. – Rory McCrossan Oct 15 '16 at 19:36
  • Thank you, I will consider enabling this option as you say. – Tariq Oct 15 '16 at 19:57

0 Answers0