Book Image

jQuery 2.0 Development Cookbook

By : Leon Revill
Book Image

jQuery 2.0 Development Cookbook

By: Leon Revill

Overview of this book

Table of Contents (17 chapters)
jQuery 2.0 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using AJAX and handling server errors


In an ideal world, your web application would never go wrong. Unfortunately, this is not the case, and web developers need to gracefully handle errors and provide the user with useful feedback.

For example, system errors occur when a server cannot be reached or a file/web page is missing. System errors are typically unavoidable and out of the user's control. They differ from application errors such as invalid data input, which a user can correct.

Getting ready

Since this recipe deals with AJAX errors and we will be calling a PHP script that does not exist, we only require HTML and JavaScript for this recipe. Create a blank HTML document named recipe-2.html and ensure that you have the latest version of jQuery downloaded and ready for use.

How to do it…

Learn how to handle AJAX errors by carefully performing the following steps:

  1. Add the following HTML code to create a simple web page with a single button that will trigger an AJAX request:

    <!DOCTYPE html&gt...