Is it possible to know that a HTTP request is from Ajax?If yes, how?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Many frameworks add a header
X-Requested-Withset toXMLHttpRequestwhen sending an AJAX request. If you are using jQuery or Microsoft frameworks, this should work. If using another framework, you’ll have to check the documentation. Since normal requests don’t have the header, a check for the presence of the header should be sufficient.If you are using your own “home-built” AJAX or the framework doesn’t do this, but does allow you to set a header, you could simply follow this convention and add your own header when making the request.