问题
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
回答1:
The X-Requested-With header is sent by default by the following frameworks:
- Dojo
- ExtJS
- jQuery
- MooTools
- Node.js
- Prototype
- YUI
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.
回答2:
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].
回答3:
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.
来源:https://stackoverflow.com/questions/7042865/what-is-the-common-http-header-for-request-by-js-libs