开发者

What is the common HTTP header for request by JS libs?

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 YU开发者_如何学运维I 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


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.


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].


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜