Skip to content

Latest commit

 

History

History
85 lines (64 loc) · 3.25 KB

jsonprequest.md

File metadata and controls

85 lines (64 loc) · 3.25 KB

Rx.DOM.jsonpRequest(url | settings)

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);

Arguments

  • 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 is true.
    • jsonp (String): The named callback parameter for the JSONP call
    • jsonpCallback (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 changed
    • url (String): URL of the request

Returns

(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 the responseType 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.

Example

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
    }
  );

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: