Creates an observable JSONP Request with the specified settings or a string URL. Note when using the method with a URL, it must contain JSONPRequest=?.
This method has two versions, one with a string URL, the other with a settings object.
// With a string URL
Rx.DOM.Request.jsonpRequest(url);
// With a settings object
Rx.DOM.Request.jsonpRequest(settings);
url
(String): A string of the URL to make the JSONP call.
OR
settings
(Object): An object with the following properties:async
(Boolean): Whether the request is async. The default istrue
.jsonp
(String): The named callback parameter for the JSONP calljsonpCallback
(String): Name of the function in the root object that JSONP will call. This is useful for when the JSONP callback is hardcoded and can't be changedurl
(String): URL of 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 which will be 'jsonp'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 'error'.status
- (Number): The HTTP status code.originalEvent
- (Object): The original event from the callback handler.
The following example uses a simple URL to retrieve a list of entries from Wikipedia.
var url = 'http://en.wikipedia.org/w/api.php?action=opensearch'
+ '&format=json'
+ '&search=reactive'
+ '&JSOPRequest=?';
Rx.DOM.jsonpRequest(url)
.subscribe(
function (data) {
data.response[1].forEach(function (item) {
console.log(item);
});
},
function (error) {
// Log the error
}
);
File:
Dist:
Prerequisites:
- If using
rx.js
rx.lite.js
|rx.lite.compat.js
NPM Packages:
NuGet Packages:
Unit Tests: