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

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 10-19-2006, 10:12 PM   PM User | #1
gorilla1
Regular Coder

 
Join Date: Jun 2002
Posts: 544
Thanks: 0
Thanked 0 Times in 0 Posts
gorilla1 is an unknown quantity at this point
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
gorilla1 is offline   Reply With Quote
Old 10-20-2006, 05:49 AM   PM User | #2
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
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.
BubikolRamios is offline   Reply With Quote
Old 10-20-2006, 03:13 PM   PM User | #3
gorilla1
Regular Coder

 
Join Date: Jun 2002
Posts: 544
Thanks: 0
Thanked 0 Times in 0 Posts
gorilla1 is an unknown quantity at this point
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
gorilla1 is offline   Reply With Quote
Old 06-03-2009, 11:19 PM   PM User | #4
solanki_21
New to the CF scene

 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
solanki_21 is an unknown quantity at this point
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
solanki_21 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 06:27 AM.


Advertisement
Log in to turn off these ads.