Identifying ajax request or browser request in grails controller

前端 未结 3 438
小蘑菇
小蘑菇 2021-02-04 04:52

I am developing a grails application which uses lot of ajax.If the request is ajax call then it should give response(this part is working), however if I type in the URL in the b

3条回答
  •  伪装坚强ぢ
    2021-02-04 05:26

    Since Grails 1.1 an xhr property was added to the request object that allows you to detect AJAX requests. An example of it's usage is below:

    def MyController {
    
      def myAction() {
        if (request.xhr) {
          // send response to AJAX request  
        } else {
          // send response to non-AJAX request
        }
      }
    }
    

提交回复
热议问题