Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    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);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •