I follow the approach given in this answer to create queue of ajax requests. But my queue is created online (depends on user actions), so I have function like below:
sendMessage = function(fieldName, oldValue, newValue) {
$(document).queue("ajaxRequests", function() {
// ...
$.ajax({
// ...
success: function(data) {
$(document).dequeue("ajaxRequests");
}
});
});
$(document).dequeue("ajaxRequests");
};
So, I'll call this sendMessage
function several times. Since I have $(document).dequeue("ajaxRequests");
at the end of this function, looks like it will not work properly - ajax will be started several times.
So, how to trigger function properly first time? Probably I should check queue length? Or, should I use fully manual queue?