From the course: JavaScript: Ajax and Fetch
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Provide error fallbacks - JavaScript Tutorial
From the course: JavaScript: Ajax and Fetch
Provide error fallbacks
- [Instructor] You can make your Ajax error handling code more useful by accounting for specific cases that are significant to your app and ensuring that your code can deal appropriately with each of them. Many types of Ajax errors can result in the requested data not being available to incorporate into the DOM. In this case, it's important to consider how you can meet the needs of your end users without remote data. For the Explore California form, the zip code data is just an extra, if the zip input box doesn't get autocompleted, users can still use the form and just fill it out manually, so there's no extra fallback required there. Now, the National Park section is already hidden by default and if the data isn't returned for whatever reason, that section of the page remains hidden, so we don't exactly have an issue. However, we could improve the user experience by including some default data that's displayed if we don't get a response. For instance, we could include the data for…
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.
Contents
-
-
-
-
-
-
(Locked)
Structure Ajax requests for performance2m 49s
-
(Locked)
View requests and responses in the browser3m 21s
-
(Locked)
Work with authorization errors2m 56s
-
(Locked)
Work with malformed requests5m 15s
-
(Locked)
Work with errors in Fetch4m 44s
-
(Locked)
Provide error fallbacks7m 15s
-
(Locked)
Challenge: Fix an Ajax request49s
-
(Locked)
Solution: Fix an Ajax request4m 29s
-
(Locked)
-
-