How do I access variables outside the ajax call?
var times;
for(var i = 0; i < 5; i++)
{
var sendDate = (new Date()).getTime();
$.ajax({
//type: "GET", //with response body
type: "HEAD", //only headers
url: "del.php",
success: function()
{
var receiveDate = (new Date()).getTime();
var responseTimeMs = receiveDate - sendDate;
times.push(responseTimeMs);
}
});
times[4]; //undefined
}
Where I call times[4] is undefined. I think because it is out of scope. How do I access the same times that was in the success function?