I’m built a little internal web application that looks up area code numbers. The problem I’m running into is that I have a LOT of area codes to go through. So much so that my app starts erroring out.
I want to build a timer into it so that I fire off a request every second or so, until the end of my array. Any ideas?
var phoneList = ["905XXXXXXX","905XXXXXXX","905XXXXXXX","905XXXXXXX","905XXXXXXX",...];
var phoneList_length = phoneList.length;
for(i=0; i < phoneList_length; i++){
$.ajax({
url: 'http://mysite.com/webservice.php',
dataType: 'jsonp',
data: 'number=' + phoneList[i] + '&index=' + i,
type: 'GET',
timeout: 10000,
success: function(data){
$('.phoneReults').append('<li>' + phoneList[data.index] + '</li>');
$('.stateReults').append('<li>' + data.region +'</li>');
$('.cityReults').append('<li>' + data.city +'</li>');
}
});
}
1 Answer