Please see the code below:
function GetSQLTable() {
var str = $("#<%=fieldGroupReferences.ClientID%>")[0].value
var res = str.split(",");
$("#LoadingImage").show();
$("#LoadingImage2").show();
for (var i = 0; i < res.length; i++) {
alert(res[i])
(function(i,res) {
setTimeout(function (i,res) {
alert(res[i])
GetSQLTable2(i, res.length,res)
}, 0)
})(i,res)
}
}
The first alert displays the correct information. The second alter errors (undefined). Why is this?
Also, I am informed that this approach should stop the webpage crashing when there are lots of AJAX requests (it is an incremental page load). However, I do not understand how setting a timeout of zero seconds between AJAX requests will help. GetSQLTable2 executes an AJAX call.
fieldGroupReferences can contain up to about 50 values.