Snippets of code and tricks that would otherwise be forgotten. Useful for me, hopefully for you too.
Thursday, May 23, 2013
JSONP XMLHttp Requests
// define a 'success' callback to handle the results of the request
success = function () {
// this is called on success
}
// add the callback function 'success' as the query parameter 'callback'
var url = "http://www.api.com/endpoint?callback=success";
// create a new SCRIPT tag, assign the url to the 'src' attribute and append to the HEAD tag
var s = document.createElement("script");
s.src = url;
document.getElementsByTagName("head")[0].appendChild(s);
// couldn't be easier
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment