Is there any way I can recognize that a request is an AJAX (something_remote_xxx) request? My application saves the pages history and needs to filter out the AJAX requests. What I do is keep a list of AJAX actions and filter them from my history list, but I always forget to update this list. So, is there any way I can detect that a request is an AJAX one from the request parameters? Thanks, Amir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
helzer <amir.helzer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So, is there any way I can detect that a request is an AJAX one from > the request parameters?Yup, if request.xhr? # this is an AJAX request else # this isn''t an AJAX request end Cheers, Tyler --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That''s the old way. You''re now supposed to do: respond_to do |wants| wants.html { .. } # normal request wants.js { ... } # Ajax request ... end http://api.rubyonrails.org/classes/ActionController/MimeResponds/InstanceMethods.html#M000080 Jason On 5/18/07, Tyler MacDonald <google.com-oTuY4Vk9bUDG8MNy1oJpyw@public.gmane.org> wrote:> > > helzer <amir.helzer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > So, is there any way I can detect that a request is an AJAX one from > > the request parameters? > > Yup, > > if request.xhr? > # this is an AJAX request > else > # this isn''t an AJAX request > end > > Cheers, > Tyler > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Amir, Try: if request.xhr? ... end Herry -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of helzer Sent: 19 May 2007 01:09 To: Ruby on Rails: Talk Subject: [Rails] How do I recognize AJAX requests Is there any way I can recognize that a request is an AJAX (something_remote_xxx) request? My application saves the pages history and needs to filter out the AJAX requests. What I do is keep a list of AJAX actions and filter them from my history list, but I always forget to update this list. So, is there any way I can detect that a request is an AJAX one from the request parameters? Thanks, Amir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, Works great. Amir> if request.xhr?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, Works great. Amir> if request.xhr?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---