如何知道是否请求是阿贾克斯asp.net mvc的? [英] how to know if the request is ajax in asp.net mvc?

查看:106
本文介绍了如何知道是否请求是阿贾克斯asp.net mvc的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人我怎么能知道,如果该请求是AJAX? (我使用jQuery的AJAX)

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

推荐答案

的jQuery做所有的AJAX调用将有以表明它是AJAX标题。检查标题是 X-要求 - 以,和值将是 XMLHtt prequest 当它是AJAX调用。

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.

需要注意的是AJAX请求是正常的获取或岗位,所以除非你(或你的AJAX库像jQuery)添加额外的报头中的要求,没有办法肯定知道它是否是AJAX与否。

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.

这篇关于如何知道是否请求是阿贾克斯asp.net mvc的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆