2013-11-23 5 views
7

Kann eine zuvor ausgeführte Ajax-Anfrage abgebrochen werden?Abbrechen einer zuvor ausgeführten Ajax-Anfrage

var xhr = $.ajax({ 
    type: "POST", 
    url: "some.php", 
    data: "name=John&location=Boston", 
    success: function(msg){ 
     alert("Data Saved: " + msg); 
    } 
}); 
+0

wie etwa 'if (XHR) {xhr.abort();}'? –

+0

Ich denke, es ist möglich, es war in ASP.NET AJAX Toolkit – Devesh

+0

Dank aller Antworten. jetzt löste es –

Antwort

5

versuchen so etwas wie dieses

 $(document).ready(function(){ 
      var xhr; // global object 

      function your_function() { 
       if(xhr && xhr.readystate != 4){ 
        xhr.abort(); 
       } 

       xhr = $.ajax({ 
        type: "POST", 
        url: "some.php", 
        data: "name=John&location=Boston", 
        success: function(msg){ 
         alert("Data Saved: " + msg); 
        } 
       }); 
      } 
     }); 
+0

Danke, es; s arbeitet für mich. –

Verwandte Themen