Tony the Pony
Tony the Pony

Reputation: 41417

How to implement an ajax request queue using jQuery

What is the best way to implement an Ajax request queue using jQuery? Specifically, I want to accomplish the following:

I'm struggling with the last requirement in particular, as the error handling mechanism in jQuery's Ajax functions is not very intuitive. Are there any examples/tutorials that could help me with this task?

Thanks!

Upvotes: 3

Views: 3602

Answers (2)

Raynos
Raynos

Reputation: 169451

I've made a few buffers like this. Some examples can be found simple task Buffer and deferred item queue.

As for error handling you can always use .ajaxError

Upvotes: 2

Emon
Emon

Reputation: 831

jQuery ajax has an error attribute where you can attach a function and the method will only fire if an error occurs. See the below example:

jQuery.ajax({
            type: "POST",
            url: "url",
            dataType:"json",
            data:{},
            success:function(data){                    
                alert("Succeed!");
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert(xhr.status);
                alert(thrownError);
            }    
        });

I hope you find this helpful.

Upvotes: 1

Related Questions