About the X-requested-with request header to differentiate between an AJAX request or a normal request

Source: Internet
Author: User

Today do spring MVC exception Unified processing this block, in the processing of the need to send the request to the zone is a traditional request or an AJAX request, online has ready-made code, I am the reference http://www.2cto.com/kf/201412/364393.html Inside of the practice. One of the

if (!( request.getHeader( "accept" ).indexOf( "application/json" ) > - 1 || ( request                      .getHeader( "X-Requested-With" ) != null && request                      .getHeader( "X-Requested-With" ).indexOf( "XMLHttpRequest" ) > - 1 ) ))

The segment code is the code that determines the type of request, but after repeated testing (tested with Goole, Firefox, 360 browser), the traditional request of the browser will also send the x-requested-with request header, So the above code does not really distinguish between a traditional request or an AJAX request. As to how to distinguish because of my limited ability has not yet come out (check the Internet, basically by the above method to distinguish)

About the X-requested-with request header to differentiate between an AJAX request or a normal request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.