jsonpTransport Plugin
Send data using JSONP via a script tag
jsonp plugin
jsonp pluginJsonp transport is a plugin for sending arbitrary data to an HTTP endpoint using a script tag. JSONP is capable of making cross-domain requests, but is subject to the data size limitations of GET requests. Only make JSONP requests to trusted endpoints, as there are serious security implications.
The endpoint must specially implement the JSONP protocol.
| Jsonp |
|---|
namespace jsonp |
| transport |
| always on |
API
jstag.jsonp(url: string, callback: JsonpTransportCallback)
params
url: string-- The URL of the request, with any data pre-encoded.callback: JsonpTransportCallback-- The callback which will be invoked with the parsed data of the response. The signature of anJsonpTransportCallbackis(data: any) => void.
returns
void
example
jstag.jsonp('https://my-trusted-domain.com/endpoint?q=data', data => {
console.log('retrieved some data with jsonp', data);
})Mechanism
This plugin works by implementing JSONP. This means assigning callbacks as properties of the global object and injecting script elements to the DOM.
Events
| Event | Fires when | Payload |
|---|---|---|
jsonp.requested | a jsonp request is initiated | The URL requested |
jsonp.finished | a jsonp request is completed | The URL requested |
Updated 13 days ago
