This is a helper library for working with JSONP.
jsonp(
"https://itunes.apple.com/search",
(data) => console.log('data', data),
{
media: "podcast",
entity: "podcast",
term: "great podcasts"
}
);
To initialize the utility, load the script:
<script src="/path/to/js/jsonp-util.js"></script>
This will register the jsonp
function into the window
.
// simple
jsonp(url, (data) => console.log(data) );
// with parameters
jsonp(url, (data) => console.log(data), { param: val } );
Type: string
URL for the request. www.example.com/api/search/
Type: function
Function to be called once the JSONP response is received.
jsonp-util supports k-ary arguments, but the first argument will be the data object returned by the JSONP response.
Type: object
Default: {}
Given the following key-value map:
let params = {
key_1 : val_1,
...,
key_n: val_n
} ;
the following string will be produced:
key_1=val_1&...&key_n=val_n
Tests
- Write some basic tests with Jasmine