Convert Jquery Ajax To Pure JavaScript Ajax
I want to convert Jquery Ajax to Pure JavaScript Ajax, i hope someone can help me, jQuery $.ajax({ type: 'GET', contentType: 'application/json; charset=utf-
Solution 1:
Try:
function jsonp(url, callback) {
var callbackName = 'jsonp_callback_' + Math.round(100000 * Math.random());
window[callbackName] = function(data) {
delete window[callbackName];
document.body.removeChild(script);
callback(data);
};
var script = document.createElement('script');
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName;
document.body.appendChild(script);
}
jsonp('https://api.meetup.com/2/open_events.json?zip=12233&page=30&category=34&time=,1w&key=1719487a4a3c39b3e241e181837529', function(data) {
alert(data.meta.description);
});
https://jsfiddle.net/tgL5v0yo/
note:
JSONP does not use XMLHttpRequests. The reason JSONP is used is to overcome cross-origin restrictions of XHRs.
Solution 2:
Problem is here:
request.onload
try replacing with
request.onreadystatechange
for to continue with request.onload
see this onreadystatechange
For more info Using XMLHttpRequest
UPDATE 1
var request = new XMLHttpRequest();
request.withCredentials = true;
request.open('GET', '/my/url', true);
Post a Comment for "Convert Jquery Ajax To Pure JavaScript Ajax"