What is the common HTTP header for request by JS l

2020-07-18 02:41发布

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

3条回答
神经病院院长
2楼-- · 2020-07-18 02:50

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.

查看更多
Explosion°爆炸
3楼-- · 2020-07-18 02:55

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

查看更多
手持菜刀,她持情操
4楼-- · 2020-07-18 02:57

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.

查看更多
登录 后发表回答