From the course: Ajax with PHP: Add Dynamic Content to Websites

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Detect Ajax requests

Detect Ajax requests

From the course: Ajax with PHP: Add Dynamic Content to Websites

Start my 1-month free trial

Detect Ajax requests

- [Narrator] In the previous chapter, we learned how Ajax works on the browser or client side. In this chapter, we'll be looking at how the server receives and responds to Ajax Requests. And we'll begin by learning how to write code which can detect an Ajax Request. When Ajax code requests a URL, it's going to hit a PHP page on the web server which can respond to the request. And we have the availability to write that PHP page in two different ways. The page could assume that all requests that come into that page are always going to be from Ajax. That's the simplest thing, right. We just say this page is only going to be accessed by Ajax and we can assume that from the start. More often though, I think you're going to want to have your page detect whether or not the request was Ajax. That way we have the ability to handle regular requests and Ajax requests differently. It might be that we only want to respond to Ajax requests. And if it's a regular request, we'll just do nothing. Or…

Contents