O'Reilly logo

ASP.NET jQuery Cookbook by Sonal Aneel Allana

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Catching and displaying AJAX errors

In certain applications, there might be a need to display the server exception, if any, raised during an AJAX call, for information/troubleshooting on the client. In this recipe, we will see how to retrieve the server exception and the XmlHTTPRequest statuses on the client.

We will go about by posting an AJAX request for a file retrieval from the server. We will intentionally throw an IO exception on the server and capture the same on the client.

Getting ready

  1. Add a web form Recipe3.aspx to the current project.
  2. Add a DropDownList to the form. Set the value of each item of the DropDownList to a filename for retrieval from the server.
  3. Thus, the complete ASPX markup of the form is as follows:
    <form id="form1" runat="server"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required