From the course: Ajax with PHP: Add Dynamic Content to Websites
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Detect Ajax requests
From the course: Ajax with PHP: Add Dynamic Content to Websites
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.