Ajax requests display a heart to indicate a favorite, but when the page is reloaded they are not remembered. Learn to add PHP code which will display a red heart when a blog post’s ID is present in the session storage when the page is first loaded.
- [Instructor] In the previous movie,…we learned how to handle the AJAX response…and to provide a visual indicator in our blog post…to let us know when it had been favorited.…However, we also realized there was a problem.…And that is that, even though I…can click the favorite button…and it'll put the red heart there for me.…If I reload the page, that red heart is lost.…And the reason why, is because the AJAX response…is putting favorite in the class for the blog post,…but when the page first loads there's no code checking…to see if something has been favorited when…it renders it for the first time.…
So the AJAX has gotten slightly more advanced…than the HTML code.…Now, let's add some code so it will always take into account…whether or not something has been favorited in the past.…Up here at the top of our index.php page,…right after we initialize the session,…I'm going to write a new function, "is_favorite."…I'm going to pass in an id…and it's just going to return true or false…depending on whether something is a favorite or not.…
- What is Ajax?
- Creating Ajax requests and responses
- Monitoring Ajax request state and events
- Responding to Ajax requests with HTML and JSON
- Building Ajax buttons
- Submitting forms with Ajax
- Implementing infinite scrolling
- Adding autosuggestions to text fields
Skill Level Intermediate
1. Ajax Defined
What is Ajax?5m 34s
2. Ajax Client
3. PHP Server
4. Ajax Button
5. Ajax Form Submission
6. Infinite Scrolling
7. Search Autosuggest
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.