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

Unlock the full course today

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

Prevent multiple requests

Prevent multiple requests

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

Start my 1-month free trial

Prevent multiple requests

- [Narrator] In the previous movie, we added infinite scrolling, but we ran into a problem. The problem is that our code is sending too many ajax requests, and we need to learn how to prevent that from happening. The problem we ran into, you can see we have blog post 104, 105 and 106, but before that we also had 104, 105 and 106. You may be wondering well how did that happen, what's going on here? We can actually see the problem a little bit better if we come over to blog posts, and we make it into a slow server by simulating that, by telling this script that it ought to sleep for two seconds. So now, let's go back over here, to firefox, let's reload our page, and the first page loads, we got blog post 101, 102 and 103, we scroll down, and it's loading, and we got 4, 5 and 6, we got 104 again. So what's happening there ? Let's try it one more time, see if we can tell. We get the first page, alright, now, I'm going to get to the bottom, and I'm going to trigger it, we're going to see…

Contents