13

In phonegap how to cancel an ajax request in program, I would like to set cancel button for control the request when it's too slow

$.ajax({
    type: "GET",
    url: url,
    success: function(m) {
        alert( "success");
    }
});
Augustus
  • 1,459
  • 2
  • 14
  • 29
oops
  • 185
  • 1
  • 11

3 Answers3

8

hi it's similar as Abort Ajax requests using jQuery,anyway This can help you

 var ab = $.ajax({  type: "GET",  url: url,  success: function(m)  {    alert( "success");  } });

//kill the request
ab.abort()
Community
  • 1
  • 1
LeNI
  • 1,144
  • 2
  • 10
  • 18
6

Store the promise interface returned from ajax request in a global variable and abort it on cancel click

var result = $.ajax({  type: "GET",  url: url,  success: function(m)  {    alert( "success");  } });


$('#cancel').click(function() {
    result.abort();
});
A. Wolff
  • 73,242
  • 9
  • 90
  • 149
Manoj Yadav
  • 6,420
  • 1
  • 20
  • 21
2
var request= $.ajax({  type: "GET",  url: url,  success: function(m)  {    alert( "success");  } });


$('#cancel').click(function() {
    request.abort();
});

this will abort the request from the client(browser) side but note : if the server has already received the request, it may continue processing the request (depending on the platform of the server) even though the browser is no longer listening for a response. There is no reliable way to make the web server stop processing a request that is in progress.

Tuhin
  • 3,170
  • 1
  • 13
  • 25