I'm trying to read in an array of URLs that contain JSON data. I'm trying to iterate through the array and load in the JSON for each URL. But I'm having issues getting error (Network Error 429 in Firebug) which lead me to believe that it was an issue with sending too many requests. I modified and simplified my code to be as listed in the jsfiddle. I'm currently trying to use setTimeout to delay the ajax calls but I am still getting errors after a certain # of ajax calls.
JSBIN : http://jsfiddle.net/s7s4cx9y/3/
var dataURL = [
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001380673/timeline?gameHash=ee3b8fd05dd64784",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001380609/timeline?gameHash=9dd207ff3ebfd598",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001380641/timeline?gameHash=828ef9a4dd73bd08",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001380241/timeline?gameHash=23c53fb7fed21f53",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001380327/timeline?gameHash=84db7440d6c8cfed",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001380474/timeline?gameHash=d90ecc8a74124bcf",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001390143/timeline?gameHash=f8a97528a608655c",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001390158/timeline?gameHash=05abd4c334651b0d",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001390159/timeline?gameHash=2bf6f0a9b1e84151",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001390160/timeline?gameHash=d4005554002839f3",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001410069/timeline?gameHash=39d2712050cd954a",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001410081/timeline?gameHash=12a38a55a9d5cf18",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001410080/timeline?gameHash=46fd67ed4c6dfb68",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001440041/timeline?gameHash=aeba4cc81f453c31",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001440036/timeline?gameHash=5debbe8da795a7cf",
"https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001440042/timeline?gameHash=53a746631e808796", "https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001440043/timeline?gameHash=4725b07311676885"
];
function test(url, x)
{
$.ajax({
url:url,
dataType:'jsonp',
async:false,
error: function (parsedjson, textStatus, errorThrown) {
$('body').append(
"<b>ERROR</b> </br> parsedJson status: " + parsedjson.status + '</br>' +
"errorStatus: " + textStatus + '</br>' +
"errorThrown: " + errorThrown + '</br></br>' +
"URL: " + url + "<br> iterator: X = " + x + "</br></br>");
},
success : function(data) {
$('body').append(
"<b>SUCCESS</b> </br>" +
"URL: " + url + "</br> iterator: X = " + x + "</br></br>");
}
});
}
for(var x = 0; x < dataURL.length; x++)
{
var proxyUrl = 'https://jsonp.afeld.me/';
var url = proxyUrl + '?url=' + encodeURIComponent(dataURL[x] ) + '&callback=?';
setTimeout(test(url, x), 10000);
}
The URLs have to be redirected through a proxy script to generate the correct jsonp as referenced in this previous question : Passing JSON from server-side (.NET) to client-side (jQuery)