What's the point of the X-Requested-With header?

后端 未结 3 1610
独厮守ぢ
独厮守ぢ 2020-11-22 05:42

JQuery and other frameworks add the following header:

X-Requested-With: XMLHttpRequest

Why is this needed? Why would a server wa

3条回答
  •  不思量自难忘°
    2020-11-22 05:58

    Some frameworks are using this header to detect xhr requests e.g. grails spring security is using this header to identify xhr request and give either a json response or html response as response.

    Most Ajax libraries (Prototype, JQuery, and Dojo as of v2.1) include an X-Requested-With header that indicates that the request was made by XMLHttpRequest instead of being triggered by clicking a regular hyperlink or form submit button.

    Source: http://grails-plugins.github.io/grails-spring-security-core/guide/helperClasses.html

提交回复
热议问题