jQuery in Action
Taking full control of an Ajax request
255
Let's put together a simple example of how some of these commands can easily
be used to report the success or failure of an Ajax request. The layout of our test
page (it's too simple to be called a lab) is as shown in figure 8.7 and is available in
the file chapter8/listing.8.6.html.
be used to report the success or failure of an Ajax request. The layout of our test
page (it's too simple to be called a lab) is as shown in figure 8.7 and is available in
the file chapter8/listing.8.6.html.
On this page we have defined three fieldsets: one that contains buttons that
will initiate Ajax requests, one that contains an area for success messages, and one
that contains an area for error messages. The
that contains an area for error messages. The
HTML
markup to set up this struc-
ture is suitably simple.
ajaxError
After the request has returned from the
server and the response contains a fail-
ure status code
server and the response contains a fail-
ure status code
A Global Callback Info object with
type set to ajaxError
type set to ajaxError
The XHR instance
The properties used by the
$.ajax()
$.ajax()
function
An exception object returned by the
XHR instance, if any
XHR instance, if any
ajaxComplete
After the request has returned from the
server and after any declared ajaxSuc-
cess or ajaxError callbacks have been
invoked
server and after any declared ajaxSuc-
cess or ajaxError callbacks have been
invoked
A Global Callback Info object with
type set to ajaxComplete
type set to ajaxComplete
The XHR instance
The properties used by the
$.ajax()
$.ajax()
function
ajaxStop
After all other Ajax processing is com-
plete and any other applicable global
callbacks have been invoked
plete and any other applicable global
callbacks have been invoked
A Global Callback Info object with
type set to ajaxStop
type set to ajaxStop
Table 8.3 Global Ajax callbacks, listed in order of firing (continued)
Global callback type
When invoked
Parameters
Figure 8.7 The initial layout of the page we'll use to examine the use of the Ajax
global callbacks