I have an associative array of URL’s, each with a unique identifier that i want to iterate through and whichever URL throws a 401 i’d like to set an alert of that specific url’s identifier. I’m stuck at the alerting portion:
for (var i=0; i<lyrs.length; i++){
$.ajax({
url: lyrs[i],
dataType: 'json',
statusCode: {
401: function(){
console.log('there was a 401 error on something');
}
}
});
}
As described in the docs, the function that you associate with
401can take the same arguments that theerrorcallback. Thus, you can write: