I am stuck here, any help would be appreciated.
I have a listbox of items, and I want to retrieve data on each item in the list via AJAX (which calls a webservice). The
Create a closure with a self-executing function:
var NumRows = list.options.length;
for ( var row = 0; row < NumRows; row ++ )
{
!function(row) {
var Value = list.options[row].value;
var xmlHttpObj = CreateXmlHttpRequestObject();
if ( xmlHttpObj != null )
{
xmlHttpObj.open( "POST", "Async.ashx?arg1=GetPhysicalPathInfo&arg2=" + Value, true );
xmlHttpObj.onreadystatechange = function ()
{
// code that needs to know what row we were from
}
}
xmlHttpObj.send();
}(row);
}
Of course, it's a major red flag that you're issuing AJAX requests from a loop. This is highly inefficient; consider making one call and returning an array from the server.