Rails detect if request was AJAX

前端 未结 5 971
悲&欢浪女
悲&欢浪女 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:11

    If you're using :remote => true in your links or forms, you'd do:

    respond_to do |format|
      format.js { #Do some stuff }
    

    You can also check before the respond_to block by calling request.xhr?.

提交回复
热议问题