跨域及CORS官方跨域

JSONP jsonp跨域的实现仅限于GET请求,不可用于POST 说明:实现的基本思路是利用html中script标签本身可跨域的特性,在发送请求时,在页面中创建script标签,追加到页面中。这实际上就像利用script标签引入外部资源 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /*main.js*/ //申明handle函数 function handle(data) { //do something.... } ele.onclick = function () { //1.创建script标签 const script = document.createElement("script") //2.修改script的src属性 script.src = "http://127.0.0.1:8000/jsonP" script.id="tempScript"//添加id方便移除 //3.追加到页面中 document.body.appendChild(script) } 1 2 3 4 5 6 7 8 9 10 11 12 /*server.js*/ app.get('/jsonP', (request, response) => { const data = { exist:1, msg:"用户名已经存在!...

2020年8月11日 · 1 min · Archai