Distinguish ajax requests from full requests in JSF custom validator

后端 未结 2 1607
北海茫月
北海茫月 2021-02-20 05:27

My validator needs to know if it is a full request or an ajax request. In my current solution I check the http request header for the X-Requested-With element:

2条回答
  •  眼角桃花
    2021-02-20 06:04

    I'd that it is a reliable way to check it. This is exactly how for example Django checks for AJAX requests:

     def is_ajax(self):
            return self.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
    

    Also listed here as such: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

提交回复
热议问题