It is important to wait for a response to be completely received before using it. Ajax uses states and events to make it easy to perform actions at key points in the request-response cycle. Learn how to see the current readyState and how to use onreadystatechange to assign functions to be performed when the state changes.
- View Offline
- Exercise Files
- [Instructor] We learned how to send requests…and we learned how to receive responses,…but there's one big piece of the Ajax puzzle…that's still missing.…And that is how do we know when a response is ready?…There's obviously going to be some elapsed time…between when the request is first made…and when the response is received.…We can't assume that the response is ready right away.…That's where states and events come in.…The XML HTTP Request Object has another function…called readyState and it will return a value…which indicates the status of the current request.…
So you simply call xhr.readyState and you'll get back…one out of five different values.…And those values are going to be the numbers zero…through four, zero, one, two, three, or four.…And here's what each one means.…If we get a zero it means the connection has been created,…but not yet opened.…One means the connection has been opened.…Two means the request has been sent and received…by the server.…Three means that the response is in progress, we've started…
- 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.