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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pass a paramter to AJAX request handler??

    I am using ajax to get some data back from the server. I want to insert this data on my page at some element in the document (where depends on where the viewer clicked on the page). So I would like to remember what element on the page was clicked. Is there a way to pass a parameter to the function that will gain control when a response comes back from the server. I find that if I add a parameter to the following statement:
    http_request.onreadystatechange = do_whatever;
    like so:
    http_request.onreadystatechange = do_whatever(parameter);
    then I get nothing at all bacl from the server. Is there some way that I can pass my parameter to the function I have indicated for http_request.onreadystatechange?

    G

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts
    i guess you could try

    Code:
    http_request.onreadystatechange(parameter) = do_whatever(parameter);
    but the logioc is that if u clicked different button, u get different response from server, so u dont need that parameter.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    BubikolRamios,

    Thanks much for your response. I tried your suggestion, but I got an error indicating that onreadystatechange is not a function (which means it cannot recognize a parameter in the way you suggested passing it). As far as not needing a parameter because a different button is clicked and therefore a different response is coming back from the server -- no, the reason I need a parameter is that I have mutliple DOM elements with buttons on them and I need to remember which element generated the request so that on return from the server I can expand the particular element on the page (with the data I am getting back from the server). I am not simply doing an innerhtml rewrite of an element on the page, as many ajax applications do. Instead, I am expanding (appending to) a specific DOM element based on which one was clicked.

    G

  • #4
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Gorilla ..
    There is another way to pass a parameter ..

    function AJAXHandler(param)
    {
    var vparam = param;
    this.Handle = function()
    {
    alert(param);
    }
    }

    var handler = new AJAXHandler("This is just a by pass");

    http_request.onreadystatechange = handler.Handle();

    Be Happy !!
    Sandeep


  •  

    Posting Permissions

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