标签:支持 return frame pos doc main data end mes
function jsonp({url, params, cb}) { return new Promise((resolve, reject) => { const script = document.createElement(‘script‘) window[cb] = (data) => { resolve(data) document.body.removeChild(script) } params = {...params, cb} // wd=b&cb=show let arrs = [] for (let key in params) { arrs.push(`${key}=${params[key]}`) } script.src = `${url}?${arrs.join(‘&‘)}` document.body.appendChild(script) }) } // 缺点:只能发送get请求 // 不安全 xss攻击 不采用 jsonp({ url: ‘https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su‘, params: {wd: ‘b‘}, cb: ‘show‘ }).then(data => { console.log(data) })
标签:支持 return frame pos doc main data end mes
原文地址:https://www.cnblogs.com/zouxinping/p/10339450.html