I have many jquery ajax requests, sent with one function.
function sendData(data){
$.post("somepage", {"data": data}, function() {}, "json")
.fail(function(jqXHR, textStatus, errorThrown){
sendData(***previuoslySentData***);
});
}
sendData(1);
sendData(2);
sendData(3);
...
as you can see, when a request fails I want to be able to send the request again with previously sent data.
how can I get back sent data on xhr error?
I thought it should be in xhr but I couldn’t find anything.
I’m also interested in any other solution for this problem.
The way you’ve wrapped your AJAX request in a function of its own, you’re effectively creating a new closure, which means that the
datavariable that you accept as an input parameter, will be still be usable in your.failcallback.