Rails detect if request was AJAX

前端 未结 5 992
悲&欢浪女
悲&欢浪女 2020-11-28 04:21

In my action I wish to only respond with processing if it was called from an AJAX request. How do I check?

I want to do something like this:

def acti         


        
5条回答
  •  悲哀的现实
    2020-11-28 05:13

    You can check for a header[X-Requested-With] to see if it is an AJAX request. Here is a good article on how to do it.

    Here is an example:

    if request.xhr?
      # respond to Ajax request
    else
      # respond to normal request
    end
    

提交回复
热议问题