I’m doing a batch of getJSON() calls within a loop.
When the calls succeed the JSON returned contains a value equal to the loop counter, but when the error handler is called I can’t seem to figure out a way to to find out which query caused it (which value the loop counter had for the failed call).
var p;
for (p = 1; p <= pagecount; p++) {
var params = {
page: p,
pagesize: 100
};
$.getJSON("http://api.travel.stackexchange.com/1.1/tags?jsonp=?",
params,
function(data) {
/* I can use data.page to know the value of page in the query */
}
).error(function(jqXHR, textStatus, errorThrown) {
/* how can I find the value "page" had in the query? */
});
}
Generate a closure for each error callback: