From the course: JavaScript: Ajax and Fetch

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Provide error fallbacks

Provide error fallbacks

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. One of those 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 isn't auto completed, users can still use the form and fill in that manually, so there's no extra fallback required here. The national park section is already hidden by default, and if the data isn't returned for whatever reason, it remains hidden so we don't 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 one of the parks in the code for the page and set up our…

Contents