Sorry if this has been covered before, i can't imagine it hasn't, but
i've been unable to find any information on it.
Can i pass my own parameters to the onComplete function specified by
Ajax.Request ?
My basic setup is i have an html element triggering an event (the ajax
update).
I have additional information encoded into the element about how it
should handle different response codes returned from the ajax event.
The problem is, i havn't figured out a way to specify the id of my
element to be passed along to the onComplete function, so right now i
just stick it in a global js variable before the ajax call and then look
it up in my on Complete function, but thats pretty hacky.
I suppose i can pass the elementId as a param to my ajax call, and have
the responder return it as part of the response codes, but that seems
kinda weak as well.
Is there no way to keep my current context when the ajax onComplete
function is triggered?
Here's my trimmed down code sample:
-----------------------------------
//global reference to the element invoking the action
var NamedActionElement;
function NamedActionHandler(theElement)
{
//set our global reference to the element so we can access it in later
functions
//since ajax calls take us to other functions and we can't seem to pass
it along
NamedActionElement = theElement;
//skip setting up my vars for the ajax call
//make the ajax call
var ajaxCall = new Ajax.Request( urlCall,
{method: 'post',
postBody: postFormData,
onComplete: NamedActionResponseHandler}
);
}
function NamedActionResponseHandler(theResponse)
{
var elementThatTriggeredEvent = NamedActionElement;
//do stuff based on values i have encoded into the element and
//the data returned in theResponse
}
----------------------
As you can see, i have to have this global variable so my onComplete
function can know which element triggered the event.
Is there a way to pass my own argument to the onComplete function?
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs