3
rehman
7y

Can anyone help me in jquery?

I'm doing a loop of trigger which are 13 in count, but every trigger event contains ajax call and what my problem is that it doesn't wait for ajax response and keep hitting trigger until last trigger fires.
so I'm having my ajax response only on last one.
What can I do for this?

Comments
  • 2
    "It doesn't wait" this is why they call it asynchronous.

    http://stackoverflow.com/questions/...
  • 0
    @jordinebot damn ;( in other conditions that's why I was doing it inside the response of ajax and was working fine, so of the example in your example they are asking for is to sisable async of ajax
  • 1
    @rehman contact me at nicholainissen@gmail.com and ill show you the solution :) essentially you want to store promises in an array and do Promise.all(arr) - if this makes no sense, shoot a mail. Im omw to werk so 40~ mins
  • 0
    @nicholai right, I have dropped an email.
  • 0
    @norman70688 I'm using plain ajax which has only sucess: to get response
  • 0
    @norman70688 well sorry to put in doubt but I meant $.ajax
  • 1
    Promise library, bro
  • 1
    @featurenotbug while bluebird is amazing, i recommended him a solution that doesn't require him to change his stack, something they might not be in a position to do. jQuery.ajax and it's derivatives return a promise, and jQuery exposes a when function that takes n params of promises and resolves when they all do, so i instructed him to push them to an array and then $.when.apply(arr)...etc and it works well :)
  • 0
    @norman70688 I did, didn't get what first link is saying but I was doing things like second link
Add Comment