Description
Basic ajax utility. Wraps jQuery#ajax
in Q promises and provides a primal API for request / response / error interceptors.
Expects a CommonJS environment, depends on both jquery
and q
.
Usage
Making a request
Arguments are passed straight to jQuery#ajax
, so call it the same way:
Adding interceptors
jqx
has three groups of interceptors:
jqxreqInterceptors -- applied to the `data` of each requestjqxresInterceptors -- applied to each success responsejqxerrInterceptors -- applied to each failed request
Success interceptors are called with the jQuery success callback arguments: (data, status, jqXhr)
. For error interceptors, the arguments order is reversed: (error, status, jqXhr)
, allowing for easier callback reuse. If a success interceptor returns a non-undefined
value, it replaces the previous data value. In other words, interceptors are also transformers, or filters.
Interceptors are applied in the same order as you add them.
jqx.addReqInterceptor([... functions])
Adds a request interceptor or multiple.
Example:
jqx
jqx.addResInterceptor([... functions])
Adds a response interceptor or multiple.
Example:
jqx
jqx.addErrInterceptor([... functions])
Adds an error interceptor or multiple.
Example:
jqx