Creates an observable for an Ajax request with either a settings object with url, headers, etc or a string for a URL.
url
(String): A string of the URL to make the Ajax call.
OR
-
settings
(Object): An object with the following propertiesasync
(Boolean): Whether the request is async. The default istrue
.body
(Object): Optional bodycrossDomain
(Boolean): true if to use CORS, else false. The default isfalse
.withCredentials
(Boolean): true if to use CORS withCredentials, else false. The default isfalse
.headers
(Object): Optional headersmethod
(String): Method of the request, such as GET, POST, PUT, PATCH, DELETE. The default is GET.password
(String): The password for the request.progressObserver
(Observer): An optionalObserver
which listen to XHR2 progress events or error timeout values.responseType
(String): The response type. Either can be 'json', 'text' or 'blob'. The default is 'text'timeout
:Number
- a number representing the number of milliseconds a request can take before automatically being terminated. A value of 0 (which is the default) means there is no timeout.url
(String): URL of the requestuser
(String): The user for the request.
(Observable): An Observable sequence with the following data.
For a successful operation, the result will contains the following:
response
- (Object): The response from the XmlHTTPRequest. Parsed into JSON if theresponseType
set.status
- (Number): The HTTP status code.responseType
- (String): The HTTP Response type.xhr
- (XmlHTTPRequest): The XmlHTTPRequest from the request.originalEvent
- (Object): The original event from the callback handler.
For a failed operation, the result will contain the following:
type
- (String): The type of rejection. This will be either 'error' or 'abort'.status
- (Number): The HTTP status code.xhr
- (XmlHTTPRequest): The XmlHTTPRequest from the request.originalEvent
- (Object): The original event from the callback handler.
The following example uses a simple URL to retrieve a list of products.
Rx.DOM.ajax({ url: '/products', responseType: 'json'})
.subscribe(
function (data) {
data.response.forEach(function (product) {
console.log(product);
});
},
function (error) {
// Log the error
}
);
File:
Dist:
Prerequisites:
NPM Packages:
NuGet Packages:
Unit Tests: