In this quick tip article we will see how we can detect AJAX request using PHP.
This trick will be very useful and handy when you want the same request to behave differently for AJAX request and normal request.
Generally we used to echo the content or some sort of flag when we deal with AJAX and in normal request execution continue to serve HTML.
So Let’s see how we can detect weather request is made using AJAX or it’s a normal request.
PHP’s $_SERVER['HTTP_X_REQUESTED_WITH'] variable is one strong sign that an AJAX request has been made from browser.
Hope you find this helpful for your work.
Avinash Zala currently working at a leading web development company as a Sr. PHP Web Developer. He is the founder of the Xpert Developer. He has completed B.E. in Information Technology. Born and brought up in Ahmedabad. He loves to code and coding is all about passion for him. Follow him on twitter at Avinash Zala & Xpert Developer.
View all posts by: Avinash