how to know if the request is ajax in asp.net mvc?

前端 未结 3 1519
孤街浪徒
孤街浪徒 2020-12-02 14:04

anybody how can I know if the request is ajax ? (I\'m using jquery for ajax)

3条回答
  •  独厮守ぢ
    2020-12-02 14:30

    All AJAX calls made by jQuery will have a header added to indicate it is AJAX. The header to check is X-Requested-With, and the value will be XMLHttpRequest when it is an AJAX call.

    Note that AJAX requests are normal GETs or POSTs, so unless you (or your AJAX library like jQuery) are adding an additional header in the request, there is no way to know for certain whether it is AJAX or not.

提交回复
热议问题