问题描述
HTTP 请求的标头中是否有任何内容可以让我区分 AJAX 调用和来自给定客户端的直接浏览器请求?无论如何,用户代理字符串通常相同吗?
Is there anything in the header of an HTTP request that would allow me to differentiate between an AJAX call and a direct browser request from a given client? Are the user agent strings usually the same regardless?
推荐答案
如果您使用 Prototype、jQuery、Mootools 或 YUI,您应该找到一个 X-Requested-With:XMLHttpRequest 标头给你的伎俩.应该可以在其他库中插入您喜欢的任何标题.
If you use Prototype, jQuery, Mootools or YUI you should find a X-Requested-With:XMLHttpRequest header which will do the trick for you. It should be possible to insert whatever header you like with other libraries.
在最低级别,给定 XMLHttpRequest 或 XMLHTTP 对象,您可以使用setRequestHeader 方法如下:
At the lowest level, given a XMLHttpRequest or XMLHTTP object, you can set this header with the setRequestHeader method as follows:
xmlHttpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
这篇关于区分 AJAX 调用/浏览器请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!





大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)