ajax - JavaScript XMLHttpRequest using JsonP - Stack Overflow JSONP does not use XMLHttpRequests. The...

Please Visit: http://ift.tt/1ajReyV



ajax - JavaScript XMLHttpRequest using JsonP - Stack Overflow



JSONP does not use XMLHttpRequests.

The reason JSONP is used is to overcome cross-origin restrictions of XHRs.

Instead, the data is retrieved via a script.

function jsonp(url, callback) {

var callbackName = 'jsonp_callback_' + Math.round(100000 * Math.random());

window[callbackName] = function(data) {

delete window[callbackName];

document.removeChild(script);

callback(data);

};

var script = document.createElement('script');

script.src = (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName;

document.appendChild(script);

}

jsonp('http://ift.tt/1teenfQ', function(data) {

alert(data);

});

http://ift.tt/1kF1nPs

http://ift.tt/1kF1nPu



ajax - JavaScript XMLHttpRequest using JsonP - Stack Overflow







from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1teenfS

via LifeLong Community

No comments:

Post a Comment