ajaxCold
Creates a cold observable for an Ajax request with either a settings object with url, headers, etc or a string for a URL.
Syntax
// Using string URL
Rx.DOM.Request.ajaxCold(url);
// Using settings object
Rx.DOM.Request.ajaxCold(settings);
Arguments
url
(String): A string of the URL to make the Ajax call.settings
(Object): An object with the following propertiesurl
(String): URL of the requestmethod
(String): Method of the request, such as GET, POST, PUT, PATCH, DELETEasync
(Boolean): Whether the request is asyncheaders
(Object): Optional headers
Returns
(Observable): An observable sequence containing the XMLHttpRequest
.
Example
The following example uses a simple URL to retrieve a list of products.
Rx.DOM.Request.ajaxCold('/products')
.subscribe(
function (xhr) {
var products = JSON.parse(xhr.responseText);
products.forEach(function (product) {
console.log(product);
});
},
function (error) {
// Log the error
}
);
Last updated
Was this helpful?