Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-14-2012, 10:50 PM   PM User | #1
terranigma
New to the CF scene

 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
terranigma is an unknown quantity at this point
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
terranigma is offline   Reply With Quote
Old 02-15-2012, 07:14 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
By omitting the " " string delimiters. You want to hand-over a function reference rather than a string.
Code:
js_newreqobject("GET","dynamic/body.html",true,js_showpreload);
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:34 AM.


Advertisement
Log in to turn off these ads.