|
onreadystatechange call as parameter?
Hallo Guys!
i need some help with my latest web project. i have written a function that creates me an xml request object. the problem is, that this function should also execute the request. my problem is, that i dont have an idea how to pass the onreadystatechange function name into the function, so i can execute it inside the function.
i tried it that way:
[CODE]
// object creation function
function js_newreqobject(type,url,async,func)
{
try
{
reqobj = new XMLHttpRequest();
}
catch(e)
{
try
{
reqobj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
reqobj = new ActiveXObject("Microsoft.XMLHTP");
}
catch(e)
{
reqobj = null;
alert("Error: XMLHttpRequest Objekt konnte nicht erstellt werden");
return 0;
}
}
}
reqobj.open(type,url,async);
reqobj.onreadystatechange = func;
reqobj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
reqobj.send(null);
}
// the call
js_newreqobject("GET","dynamic/body.html",true,"js_showpreload");
[ICODE]
(reqobj is global)
the problem is simple:
js_showpreload didnt execute. this function exists an is defined before js_newreqobject and the call
how can i get this to work?
Greets & sorry for my bad english
terra
|