I am curious what gets passed back from an completed Ajax.Request call? I am using "onComplete: handleSuccess" in my request: var handleSuccess = function(originalRequest){ $(''content'').innerHTML = originalRequest.responseText; } but is there other data in that "originalRequest" object that might be useful? perhaps the original parameters, the URL etc. Is there a quick way to inspect it? ( I tried originalRequest.inspect () with no luck.. ) Thanks!! ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Alex Duffield wrote:> I am curious what gets passed back from an completed Ajax.Request call?All of the Ajax.Request event handlers receive two arguments. The first is the XMLHttpRequest object used to make the Ajax request. This is often referred to as the transport in the Prototype library. You can find details about this object at: http://en.wikipedia.org/wiki/XMLHttpRequest The second argument passed in is a JavaScript data structure created from a JSON string. This JSON string is received from the X-JSON header in the HTTP response for your Ajax call. Finally, all event handlers for the Ajax.Request object are executed in the context of the Ajax.Request object. That means that the "this" identifier can be used to query the Ajax.Request object that made the request. There is one exception to what I just stated. The onException callback just receives one argument which is the exception that was generated.> I am using "onComplete: handleSuccess" in my request:You may want to consider using onSuccess instead of onComplete. onComplete executes when the XMLHttpRequest object has completed the request but that request is not necessarily successful. For example it could have received a 404 response and still called onComplete. When you use onSuccess your callback will only be executed when you get back a successful response from the webserver. You can use onFailure to detect problems such as 404 responses. Eric
Eric, thanks for the answer. I was hoping to be able to get the options (parameters in particular) that where used in the origian request. Oh well. Ill find another solution. ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com On 5-Aug-06, at 8:23 AM, Eric Anderson wrote:> Alex Duffield wrote: >> I am curious what gets passed back from an completed Ajax.Request >> call? > > All of the Ajax.Request event handlers receive two arguments. The > first is the XMLHttpRequest object used to make the Ajax request. > This is often referred to as the transport in the Prototype > library. You can find details about this object at: > > http://en.wikipedia.org/wiki/XMLHttpRequest > > The second argument passed in is a JavaScript data structure > created from a JSON string. This JSON string is received from the X- > JSON header in the HTTP response for your Ajax call. > > Finally, all event handlers for the Ajax.Request object are > executed in the context of the Ajax.Request object. That means that > the "this" identifier can be used to query the Ajax.Request object > that made the request. > > There is one exception to what I just stated. The onException > callback just receives one argument which is the exception that was > generated. > >> I am using "onComplete: handleSuccess" in my request: > > You may want to consider using onSuccess instead of onComplete. > onComplete executes when the XMLHttpRequest object has completed > the request but that request is not necessarily successful. For > example it could have received a 404 response and still called > onComplete. When you use onSuccess your callback will only be > executed when you get back a successful response from the > webserver. You can use onFailure to detect problems such as 404 > responses. > > Eric > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Michael Peters
2006-Aug-05 16:29 UTC
Re: Re: onComplete: handleSuccess - What gets passed?
Alex Duffield wrote:> Eric, thanks for the answer. I was hoping to be able to get the options > (parameters in particular) that where used in the origian request. Oh > well. Ill find another solution.You could just use a closure: new Ajax.Request( url, { parameters: params, ... onComplete: function(response) { // you can access the ''params'' // in here }, } ); Now, if you pass a function by name instead for your onComplete value, you can just wrap it in an anonymous function like so onComplete: function(response) { // use ''params'' yourOnComplete(response, ...); } -- Michael Peters Developer Plus Three, LP
That looks like it will work.. or I could just pass the prams on to my complete function.. NO? onComplete: function(response) { yourOnComplete(response,prams); } ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com On 5-Aug-06, at 9:29 AM, Michael Peters wrote:> > > Alex Duffield wrote: >> Eric, thanks for the answer. I was hoping to be able to get the >> options >> (parameters in particular) that where used in the origian >> request. Oh >> well. Ill find another solution. > > You could just use a closure: > > new Ajax.Request( > url, > { > parameters: params, > ... > onComplete: function(response) { > // you can access the ''params'' > // in here > }, > } > ); > > Now, if you pass a function by name instead for your onComplete > value, you can > just wrap it in an anonymous function like so > > onComplete: function(response) { > // use ''params'' > yourOnComplete(response, ...); > } > > -- > Michael Peters > Developer > Plus Three, LP > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Michael Peters
2006-Aug-05 16:37 UTC
Re: Re: onComplete: handleSuccess - What gets passed?
Alex Duffield wrote:> That looks like it will work.. > > or I could just pass the prams on to my complete function.. NO? > > onComplete: function(response) { > yourOnComplete(response,prams); > }Exactly. That''s using the closure. -- Michael Peters Developer Plus Three, LP
cheers! I owe you a beer. ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com On 5-Aug-06, at 9:37 AM, Michael Peters wrote:> > > Alex Duffield wrote: >> That looks like it will work.. >> >> or I could just pass the prams on to my complete function.. NO? >> >> onComplete: function(response) { >> yourOnComplete(response,prams); >> } > > Exactly. That''s using the closure. > > -- > Michael Peters > Developer > Plus Three, LP > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Alex Duffield wrote:> Eric, thanks for the answer. I was hoping to be able to get the options > (parameters in particular) that where used in the origian request. Oh > well. Ill find another solution.Hmmmm.... I guess I was not very clear. The following statement was the primary answer to your question: I wrote:>> Finally, all event handlers for the Ajax.Request object are executed >> in the context of the Ajax.Request object. That means that the "this" >> identifier can be used to query the Ajax.Request object that made the >> request.Since your callbacks are executed in the context of the Ajax.Request object you can access the Ajax.Request object with the "this" identifier. The Ajax.Request object of course stores all your options (plus various other info). So if you want the parameters you can do: function mySuccess(transport, json) { alert(''Ajax request with parameters '' + this.options.parameters + '' finished executing''); } new Ajax.Request(url, {onSuccess: mySuccess}); Eric
Wonderful!! Now I owe you a beer to! Thanks :-) ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com On 5-Aug-06, at 10:43 AM, Eric Anderson wrote:> Alex Duffield wrote: >> Eric, thanks for the answer. I was hoping to be able to get the >> options (parameters in particular) that where used in the origian >> request. Oh well. Ill find another solution. > > Hmmmm.... I guess I was not very clear. The following statement was > the primary answer to your question: > > I wrote: >>> Finally, all event handlers for the Ajax.Request object are >>> executed in the context of the Ajax.Request object. That means >>> that the "this" identifier can be used to query the Ajax.Request >>> object that made the request. > > Since your callbacks are executed in the context of the > Ajax.Request object you can access the Ajax.Request object with the > "this" identifier. The Ajax.Request object of course stores all > your options (plus various other info). So if you want the > parameters you can do: > > function mySuccess(transport, json) { > alert(''Ajax request with parameters '' + > this.options.parameters + '' finished executing''); > } > new Ajax.Request(url, {onSuccess: mySuccess}); > > Eric > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs