Hi all, This question might be a long shot, but I''m going to ask it anyway. In my application, I''ve created a before_filter that does some magic. It looks like this: if request.xhr? then render :update do |page| page.redirect_to url_for_thingy end else redirect_to redirect_to url_for_thingy end This works perfectly, however, I have one annoyance. On the server side, I don''t know if the xhr request coming in is from an AjaxUpdater or AjaxRequest (using prototype here). It''s possible that the browser will update a DOM element or that it just expects some javascript code. When an AjaxUpdater is used, the element is updated and the javascript is executed (so the redirect is done), but it just doesn''t look so nice. Anyone got a solution? Greetings, Wouter -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Jun-17 17:47 UTC
Re: Serverside AjaxRequest or AjaxUpdater detections
On Jun 17, 6:41 pm, Wouter de Bie <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> This works perfectly, however, I have one annoyance. On the server side, > I don''t know if the xhr request coming in is from an AjaxUpdater or > AjaxRequest (using prototype here). It''s possible that the browser will > update a DOM element or that it just expects some javascript code. When > an AjaxUpdater is used, the element is updated and the javascript is > executed (so the redirect is done), but it just doesn''t look so nice. >You could look at the Accept header sent by the browser - in the Ajax.Request case it should be something like application/javascript Fred> Anyone got a solution? > > Greetings, > > Wouter > -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> You could look at the Accept header sent by the browser - in the > Ajax.Request case it should be something like application/javascriptrequest.env[''HTTP_ACCEPT''] has the same value for a normal GET, AjaxUpdater or AjaxRequest.. Any other suggestions? -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Jun-19 09:03 UTC
Re: Serverside AjaxRequest or AjaxUpdater detections
On Jun 19, 9:55 am, Wouter de Bie <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Frederick Cheung wrote: > > You could look at the Accept header sent by the browser - in the > > Ajax.Request case it should be something like application/javascript > > request.env[''HTTP_ACCEPT''] has the same value for a normal GET, > AjaxUpdater or AjaxRequest.. > > Any other suggestions?Hack prototype to so that one of the two sets an http header of your choice ? Fred> -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> Hack prototype to so that one of the two sets an http header of your > choice ? > > FredYeah, I was thinking the same thing. Maybe adding an X_HTTP_FOO header is an nice option.. Let''s see if I can do it so that it doesn''t break when upgrading Rails to a future release. -- Posted via http://www.ruby-forum.com/.
Possibly Parallel Threads
- AJAX Exception just started with Safari and Firefox on OS X, no problem on other machines
- script.aculo.us 1.5 release candidate 1
- ServerSide ACLs for -L type port forwarding
- chan_read_failed for istate 3 on serverside when scp'ing file
- Beginner question: serverside singletons?