Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 1.16 KB

ajax.md

File metadata and controls

36 lines (28 loc) · 1.16 KB

Rx.DOM.Request.ajax(url | settings)

# [Ⓣ][1]

Creates a hot observable for an Ajax request with either a settings object with url, headers, etc or a string for a URL.

Arguments

  1. url (String): A string of the URL to make the Ajax call.

  2. settings (Object): An object with the following properties

     - `url` *(String)*: URL of the request
     - `method` *(String)*: Method of the request, such as GET, POST, PUT, PATCH, DELETE
     - `async` *(Boolean)*: Whether the request is async
     - `headers` *(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.ajax('/products')
	.subscribe( 
		function (xhr) {

			var products = JSON.parse(xhr.responseText);

			products.forEach(function (product) {
				console.log(product);
			});
		},
		function (error) {
			// Log the error
		}
	);