From the course: JavaScript: Async
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Using error checking with multiple callbacks - JavaScript Tutorial
From the course: JavaScript: Async
Using error checking with multiple callbacks
- [Instructor] Our Explore California site uses an Ajax request to get weather, and a callback to work with the data received. But what happens when the response contains something other than the data we expect? We could receive an authentication error, a notification that the service is down, or any one of a number of other responses that don't include the data we're looking for. To deal with this, it's common to use error checking in conjunction with multiple callbacks. So, when the response comes in, instead of simply assuming we have good data and calling the success callback, we can check what kind of response we got. If our Ajax request results in a 200 response, then we know the request succeeded, and we have data, so we can call the success callback. But for any other response code, we may or may not be getting the data we expect. And we're probably not. So, we want to instead call a different callback…
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.