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
helzer [email protected] 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
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