Show:
Module: jsonp-url
Parent Module: jsonp

<p>Provides a JSONPRequest class for repeated JSONP calls, and a convenience method Y.jsonp(url, callback) to instantiate and send a JSONP request.</p>

<p>Both the constructor as well as the convenience function take two parameters: a url string and a callback.</p>

<p>The url provided must include the placeholder string "{callback}" which will be replaced by a dynamically generated routing function to pass the data to your callback function. An example url might look like "http://example.com/service?callback={callback}".</p>

<p>The second parameter can be a callback function that accepts the JSON payload as its argument, or a configuration object supporting the keys:</p> <ul> <li>on - map of callback subscribers <ul> <li>success - function handler for successful transmission</li> <li>failure - function handler for failed transmission</li> <li>timeout - function handler for transactions that timeout</li> </ul> </li> <li>format - override function for inserting the proxy name in the url</li> <li>timeout - the number of milliseconds to wait before giving up</li> <li>context - becomes <code>this</code> in the callbacks</li> <li>args - array of subsequent parameters to pass to the callbacks</li> <li>allowCache - use the same proxy name for all requests? (boolean)</li> </ul>

Methods

_defaultCallback

(
  • url
)
Function protected

<p>Parses the url for a callback named explicitly in the string. Override this if the target JSONP service uses a different query parameter or url format.</p>

<p>If the callback is declared inline, the corresponding function will be returned. Otherwise null.</p>

Parameters:

  • url String

    the url to search in

Returns:

Function:

the callback function if found, or null

_defaultCallback

(
  • url
  • config
)
Function

Provided by the jsonp module.

Defined in yui3/src/jsonp/js/jsonp.js:108

Override this method to provide logic to default the success callback if it is not provided at construction. This is overridden by jsonp-url to parse the callback from the url string.

Parameters:

  • url String

    the url passed at construction

  • config Object

    (optional) the config object passed at construction

Returns:

Function:

_format

(
  • url
  • proxy
)
String protected

URL formatter that looks for callback= in the url and appends it if not present. The supplied proxy name will be assigned to the query param. Override this method by passing a function as the "format" property in the config object to the constructor.

Parameters:

  • url String

    the original url

  • proxy String

    the function name that will be used as a proxy to the configured callback methods.

Returns:

String:

fully qualified JSONP url

_format

(
  • url
  • proxy
  • args
)
String protected

Provided by the jsonp module.

Defined in yui3/src/jsonp/js/jsonp.js:229

Default url formatter. Looks for callback= in the url and appends it if not present. The supplied proxy name will be assigned to the query param. Override this method by passing a function as the "format" property in the config object to the constructor.

Parameters:

  • url String

    the original url

  • proxy String

    the function name that will be used as a proxy to the configured callback methods.

  • args Any multiple

    additional args passed to send()

Returns:

String:

fully qualified JSONP url

_init

(
  • url
  • callback
)
protected

Provided by the jsonp module.

Defined in yui3/src/jsonp/js/jsonp.js:46

Set up the success and failure handlers and the regex pattern used to insert the temporary callback name in the url.

Parameters:

  • url String

    the url of the JSONP service

  • callback Object | Function

    Optional success callback or config object containing success and failure functions and the url regex.

send

(
  • args
)
chainable

Provided by the jsonp module.

Defined in yui3/src/jsonp/js/jsonp.js:121

Issues the JSONP request.

Parameters:

  • args Any multiple

    any additional arguments to pass to the url formatter beyond the base url and the proxy function name

Properties

_pattern

RegExp protected

RegExp used by the default URL formatter to insert the generated callback name into the JSONP url. Looks for a query param callback=. If a value is assigned, it will be clobbered.

Default: /\bcallback=.*?(?=&|$)/i

_requests

Object private

Provided by the jsonp module.

Defined in yui3/src/jsonp/js/jsonp.js:60

Map of the number of requests currently pending responses per generated proxy. Used to ensure the proxy is not flushed if the request times out and there is a timeout handler and success handler, and used by connections configured to allowCache to make sure the proxy isn't deleted until the last response has returned.

_template

String protected

Template used by the default URL formatter to add the callback function name to the url.

Default: "callback={callback}"

_timeouts

Object private

Provided by the jsonp module.

Defined in yui3/src/jsonp/js/jsonp.js:73

Map of the number of timeouts received from the destination url by generated proxy. Used to ensure the proxy is not flushed if the request times out and there is a timeout handler and success handler, and used by connections configured to allowCache to make sure the proxy isn't deleted until the last response has returned.