JS 库请求的常见 HTTP 标头是什么?
使用 Prototype JavaScript 框架 我注意到,Ajax 请求通过名为 X 的标头进行了丰富-请求-与
。
其他 JavaScript 库(如 jQuery、dojo 和 YUI)是否会向其 Ajax 请求添加标头?它总是被称为X-Requested-With
吗?这是一个标准吗?
Prototype 的完整标头:
X-Requested-With: XMLHttpRequest
X-Prototype-Version: 1.5.0_rc0
Using the Prototype JavaScript framework I've noticed, that the Ajax requests are enriched with a header called X-Requested-With
.
Do other JavaScript libraries like jQuery, dojo and YUI add headers to their Ajax requests? Is it always called X-Requested-With
? Is this a standard?
The full header by Prototype:
X-Requested-With: XMLHttpRequest
X-Prototype-Version: 1.5.0_rc0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
X-Requested-With 标头默认由以下框架发送:
像往常一样,请记住框架并不强制发送它,有时框架的用户可以覆盖它,客户端/防火墙/代理/服务器可能会影响它,甚至有 已知浏览器错误。
The X-Requested-With header is sent by default by the following frameworks:
As usual, keep in mind that it is not mandatory for frameworks to send it, that sometimes the framework's user can override it, that client/firewall/proxy/server may affect it, and there are even known browser bug(s) for it.
“X-Requested-With”标头的“X-”部分是标记非标准标头的约定。
这篇维基百科文章指出,此标头主要用于识别 Ajax 请求。大多数 JavaScript 框架都会发送带有 XMLHttpRequest 值的标头[用于 AJAX 调用]。
The "X-" portion of the "X-Requested-With" header is a convention that marks non-standard headers.
This Wikipedia article notes that this header is mainly used to identify Ajax requests. Most JavaScript frameworks send this header with value of XMLHttpRequest [for AJAX calls].
X 前缀表示非标准,但按照惯例可以说它是标准的。
其他 JS 框架(包括 jQuery 和 MooTools)也附加了此内容。服务器端框架(包括 Rails、zend 和 symfony 等)会查找它来确定请求是否是 XMLHttpRequest。
The X prefix denotes non-standard, but it could be said it's standard by convention.
Other JS frameworks including jQuery and MooTools append this as well. It's looked for by server side frameworks (including rails, zend, and symfony, to name a few) to determine if a request is XMLHttpRequest.