javascript - How to write JSONP Ajax request on pure js? -
this question has answer here:
$.ajax( { url : '', data: {}, datatype:'jsonp', jsonpcallback: 'callbackname', type: 'post' ,success:function (data) { console.log('ok'); }, error:function () { console.log('error'); } });
how write same functionality in pure js?
in particular case, aren't making ajax call @ all, instead you're making jsonp request. luckily, these incredibly easy replicate , work in browsers.
var s = document.createelement("script"), callback = "jsonpcallback_" + new date().gettime(), url = "http://forexplay.net/ajax/quotes.php?callback=" + callback; window[callback] = function (data) { // worked! console.log(data); }; s.src = url; document.body.appendchild(s);
Comments
Post a Comment