var ajax_request = ""; function go_ajax(){ if(typeof ajax_request !== 'undefined'){ ajax_request.abort(); } ajax_request = $.ajax({ type: 'post', url: '/УРЛ_САЙТА', data: {par: params_}, success: function(data) { //действия по success } }); 


How to cancel the request for the server .... ajax_request.abort () stops "listening" for the client, the server does not complete the previous task yet, remains busy

  • Ignore. What is the question and the answer :) - Zowie
  • The question is not pleased. In my opinion, quite specific ..... If there is an opportunity to cancel the sent ajax request, after the script received and started processing the data, .... it may be more understandable .... But most likely @ forum3 is right - Maksym Prus
  • And what did not please the answer? :) Well, ok, I understand the server in PHP? - Zowie

2 answers 2

If the request is gone, do not stop. Ie if the script received the data and started to do something, then do not stop.

Try to change the logic so that the request is made only when necessary.

    Here it is possible:

     if (ajax_request) { ajax_request.abort(); } 

    And so that the server does not perform the operation further: then ignore_user_abort (false);

    this is for php. For others, I do not know, but I am sure that there is something similar too. It is also worth noting that by default ignore_user_abort is set to false

    • one
      Report a bug Notes PHP will not be able to detect a user disconnection until an attempt is made to send information to the client. Simply using the echo expression does not guarantee the sending of information, see the flush () function. The script will do the job anyway. Only change logic - forum3 p.m.
    • one
      I can be wrong, it can be bypassed somehow - forum3
    • one
      the link is a good example, you can try it;) Example # 1 I would write something like this: ignore_user_abort (false); for ($i = 0; $i < 20; $i++) { sleep(1); } $f = fopen('/tmp/test', 'a+'); fwrite($f, "script has been finished at ".date('r')."\n"); fclose($f); ie, if we cut (press esc in the browser) immediately after the start of the download (up to 20 seconds), then the record should not appear in the file. if the record does not appear, then everything actually works correctly. And I didn’t quite understand the analogy with echo - Alex Kapustin