Quote:
Originally Posted by Basscyst
I use this little function I wrote, I guess it's creating a new one each time. The only thing I don't like about it is the eval for the call back function, but I can't think of another way to reliably pass values from the initiation of the request to the call back function.
Code:
var x=4;
getReqObjPost("someurl.asp","param1=1¶m2=2","callBack(xml,"+x+")");
|
Code:
var x=4;
getReqObjPost("someurl.asp","param1=1¶m2=2",function() { callBack(xml,x) });
Works fine. The anonymous function creates a closure over all the variables available in the current scope (e.g. x), which then is referenced as an argument to callBack.