jQuery 源码中X-Requested-With header 的作用

                // X-Requested-With header
                // For cross-domain requests, seeing as conditions for a preflight are
                // akin to a jigsaw puzzle, we simply never set it to be sure.
                // (it can always be set on a per-request basis or even using ajaxSetup)
                // For same-domain requests, won't change header if already provided.
                if ( !options.crossDomain && !headers[ "X-Requested-With" ] ) {
                    headers[ "X-Requested-With" ] = "XMLHttpRequest";
                }

请问这段代码是什么意思呢?

阅读 2.7k
2 个回答

添加一个http头用来说明这次的请求是通过XMLHttpRequest进行的

后端根据它判断是一次AJAX请求

推荐问题