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.

Handle button Ajax response

Handle button Ajax response

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

Start my 1-month free trial

Handle button Ajax response

- [Instructor] In the previous movie, we were able to capture and store the correct ID in the session. But at the moment, the user doesn't have any indication whether the Ajax request succeeded or not. In this movie, we're going to make that clear. One of the best ways to make it clear that an item has changed is to mark it with a different class in CSS. And it's best if we can do that at the very top level, the parent of the item, in this case, the blog post class. So what we want to do is add a class to this blog post to know that it's a favorite, so it makes sense that the class would be called favorite. We want to do that if we get back a true result. So if the result comes back and it's equal to the string true, not the actual true or false, but the string true, then we want to take that parent that we've been working with, remember that's the parent element of this Favorite button, we want to take that parent and we want to say that its classList ought to add, and then let's put…

Contents