Created
April 20, 2019 08:54
-
-
Save kmokidd/a210b24df894158de8cd09a752095bd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encodeUrl(url, params) { | |
let paramStr = '' | |
for(let key in params) { | |
paramStr+=key+'='+params[key]+'&' | |
} | |
return url+'?'+paramStr.slice(0, paramStr.length-1) | |
} | |
function jsonp(url, params, cb) { | |
url = encodeUrl(url, params) | |
var script = document.createElement('script') | |
script.setAttribute('src', url) | |
document.querySelector('body').appendChild(script) | |
window.jsonp = function(data) { | |
if(cb) cb(data) | |
else document.querySelector('div').innerHTML = data; | |
} | |
} | |
jsonp("http://127.0.0.1:3000/data.js", {pkg:123, chid:321}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment