Ajax

Páginas: 2 (335 palabras) Publicado: 27 de abril de 2012
Callback Function Queues

The beforeSend, error, dataFilter, success and complete options all accept callback functions that are invoked at the appropriate times.

As of jQuery 1.5, the error(fail), success (done), and complete (always, as of jQuery 1.6) callback hooks are first-in, first-out managed queues. This means you can assign more than one callback for each hook. See Deferred objectmethods, which are implemented internally for these $.ajax() callback hooks.

The this reference within all callbacks is the object in the context option passed to $.ajax in the settings; if contextis not specified, this is a reference to the Ajax settings themselves.

Some types of Ajax requests, such as JSONP and cross-domain GET requests, do not use XHR; in those cases the XMLHttpRequestand textStatus parameters passed to the callback are undefined.

Here are the callback hooks provided by $.ajax():

beforeSend callback is invoked; it receives the jqXHR object and the settingsmap as parameters.
error callbacks are invoked, in the order they are registered, if the request fails. They receive the jqXHR, a string indicating the error type, and an exception object ifapplicable. Some built-in errors will provide a string as the exception object: "abort", "timeout", "No Transport".
dataFilter callback is invoked immediately upon successful receipt of responsedata. It receives the returned data and the value of dataType, and must return the (possibly altered) data to pass on to success.
success callbacks are then invoked, in the order they areregistered, if the request succeeds. They receive the returned data, a string containing the success code, and the jqXHR object.
complete callbacks fire, in the order they are registered, when the requestfinishes, whether in failure or success. They receive the jqXHR object, as well as a string containing the success or error code.

For example, to make use of the returned HTML, we can implement a...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • ajax
  • Ajax
  • Ajax
  • Ajax
  • Ajax
  • ajax
  • Ajax
  • Ajax

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS