jQuery in Action

Taking full control of an Ajax request
249
Between the
load()
command and the various
GET
and
POST
jQuery Ajax func-
tions, we can exert some measure of control over how our request is initiated and
how we're notified of its completion. But for those times when we need full con-
trol over an Ajax request, jQuery has a means for us to get as picky as we want.
8.4 Taking full control of an Ajax request
The functions and commands that we've seen so far are convenient for many
cases, but there may be times when we want to take control of the nitty-gritty
details into our own hands.
In this section, we'll explore how jQuery lets us exert such dominion.
8.4.1 Making Ajax requests with all the trimmings
For those times when we want or need to exert a fine-grained level of control over
how we make Ajax requests, jQuery provides a general utility function for making
Ajax requests named
$.ajax()
. Under the covers, all other jQuery features that
make Ajax requests eventually use this function to initiate the request. Its syntax is
as follows:


Command syntax: $.post
$.post(url,parameters,callback)
Initiates a POST request to the server using the specified URL with any parameters passed
within the body of the request.
Parameters
url
(String) The URL of the server-side resource to contact via the
POST method.
parameters
(Object|String) An object whose properties serve as the name/value pairs
used to construct the body of the request, or a preformatted and encoded
query string.
callback
(Function) A function invoked when the request completes. The response
body is passed as the single parameter to this callback, and the status as
the second.
Returns
The XHR instance.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.