I have the following scenario in my javascript:
You should use when
or success
not both. It sounds like (although code samples would make this clearer) you are attaching two separate listeners to the ajax call, but you only want one to execute after the other.
I'd either roll both into one event like:
$.ajax( ... , function(){
// success
// prep stuff here
$.ajax( ... , function(){
// second success
// do final stuff here
});
});
Or wrap you ajax call inside another promise (this may require a bit more reading around jQuery promises).
But if you do something like
$.when($.ajax( ... , function(){
// thing a
}).then(function(){
// thing b
});
Thing a and b will execute at the same time, because they are designed for pretty much the same thing.