DWQA QuestionsCategory: ProgramThe function of x-requested-with header in jQuery source code
undefinedvar asked 2 months ago
                // 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";
                }

What does this code mean?

2 Answers
Branson answered 2 months ago

Add an HTTP header to indicate that the request is made through XMLHttpRequest

alexnevsky answered 2 months ago

According to it, the back end judges that it is an Ajax request