Provides a JSONPRequest class for repeated JSONP calls, and a convenience method Y.jsonp(url, callback) to instantiate and send a JSONP request.
Both the constructor as well as the convenience function take two parameters: a url string and a callback.
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}".
The second parameter can be a callback function that accepts the JSON payload as its argument, or a configuration object supporting the keys:
this
in the callbacks_defaultCallback
url
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.
If the callback is declared inline, the corresponding function will be returned. Otherwise null.
url
String
the url to search in
the callback function if found, or null
_defaultCallback
url
config
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.
_format
url
proxy
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.
fully qualified JSONP url
_format
url
proxy
args
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.
fully qualified JSONP url
_init
url
callback
Set up the success and failure handlers and the regex pattern used to insert the temporary callback name in the url.
send
args
Issues the JSONP request.
args
Any
multiple
any additional arguments to pass to the url formatter beyond the base url and the proxy function name
_pattern
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
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
Template used by the default URL formatter to add the callback function name to the url.
Default: "callback={callback}"
_timeouts
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.