Passing arguments to the function that handles the "onreadystatechange" event.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   olorin_here
Posted On:   Friday, February 16, 2007 07:58 AM

I want to know whether there is a way to pass some arguments to the function that handles the "onreadystatechange" event. I want to assign the responseText to an attribute of the object that is received as an argument to the handler function. I am talking about something like this: .............. .............. .............. xhrObj.onreadystatechange = HandlerFunction(elementReference); .............. .............. .............. function HandlerFunction(elementReference) { if(re   More>>


I want to know whether there is a way to pass some arguments to the function that handles the "onreadystatechange" event.



I want to assign the responseText to an attribute of the object that is received as an argument to the handler function.



I am talking about something like this:







..............

..............

..............

xhrObj.onreadystatechange = HandlerFunction(elementReference);

..............

..............

..............



function HandlerFunction(elementReference)

{

if(readyState is appropriate)

{

elementReference.setAttribute("label",value");

}

}










Please let me know I can do something like this or there is a around this.



The purpose is this:



I have a set of similar elements. I collect them using
getElementsByTagName

Then I need to get the value of a particular attribute for each of the above elements, for which I place a XHR for each request. The problem is in assigning the right responseText to the proper element that it belongs to.



Any help would be great

Thank you

   <<Less

Re: Passing arguments to the function that handles the "onreadystatechange" event.

Posted By:   Anonymous  
Posted On:   Saturday, February 24, 2007 11:30 AM


var xhrObj;
..........
void function(){// emulate local block with anonimus function
var context=...
var arg1=elementReference;
var arg2=...
xhrObj.onreadystatechange = function(){
HandlerFunction.call(context,arg1,arg2);
}
}()//end of local block and run it


If You use array - be excelent with index in closure(last index most be geopardic actual for all handler).

Re: Passing arguments to the function that handles the "onreadystatechange" event.

Posted By:   Anonymous  
Posted On:   Friday, February 16, 2007 11:08 AM


aovc.js.html.ajax.sendRequest = function(url,params,callback,context,args)
{
...
var req= getHTTPRequest()
...
req.onreadystatechange=function()
{
...
if (req.readyState == 4
{
fcall.apply(context,ar);
}
}

req.open(...);
req.setRequestHeader(...);
req.send(...);
}
About | Sitemap | Contact