3 Replies - 397 Views - Last Post: 24 October 2013 - 03:00 AM

#1 buzzard king  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-October 13

stop all other jQuery Ajax POSTs, only run one

Posted 24 October 2013 - 02:37 AM

hi, basically how do I stop all jQuery ajax statements from running if a another one starts :red_indian:

$.ajax({
    url: "[PHP FILE]",
    type: "POST",
    data: data,
    success: function (html) {
	//code
    }
});



thing is on my online app there are buttons very close to each other that can get clicked multiple times and the user can click one then another straight away and it causes a queue of POST which looks dumb because it displays each one causing lag.

so what i want to do is when a user clicks a button something needs to pull out a gun and kill all the other POSTs :gun_bandana: and just load the one they clicked :gunsmilie:

Is This A Good Question/Topic? 0
  • +

Replies To: stop all other jQuery Ajax POSTs, only run one

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3490
  • View blog
  • Posts: 10,058
  • Joined: 08-June 10

Re: stop all other jQuery Ajax POSTs, only run one

Posted 24 October 2013 - 02:43 AM

jQuery’s jqXHR object should have an abort() method (inherited from the regular XMLHttpRequest object). otherwise I can only think of calling the reject() method of the Promise interface.
Was This Post Helpful? 0
  • +
  • -

#3 buzzard king  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-October 13

Re: stop all other jQuery Ajax POSTs, only run one

Posted 24 October 2013 - 02:57 AM

View PostDormilich, on 24 October 2013 - 02:43 AM, said:

jQuery’s jqXHR object should have an abort() method (inherited from the regular XMLHttpRequest object). otherwise I can only think of calling the reject() method of the Promise interface.


how would this work? I thought this would be a simple fix such as stopping .animate() with .stop()
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3490
  • View blog
  • Posts: 10,058
  • Joined: 08-June 10

Re: stop all other jQuery Ajax POSTs, only run one

Posted 24 October 2013 - 03:00 AM

it should work like that.
$ajax = $.ajax({ ... });
// later
$ajax.abort();

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1