为什么在使用fetch fetch的情况下提出get请求会给我带来错误,同时以src的形式向url注入脚本标签,而不是src?
如果我以这样的方式注入脚本:
((global, url) => {
let s = document.createElement('script')
s.src = url
global.document.body.appendChild(s)
})(window, 'https://example.com')
该请求将恰好通过,并且脚本将在对“ https://example.com”请求的响应中插入...但是,如果我尝试进行显式< strong>提取请求同一URL我会遇到CORS错误吗?为什么会发生?
If I inject a script programmatically like this:
((global, url) => {
let s = document.createElement('script')
s.src = url
global.document.body.appendChild(s)
})(window, 'https://example.com')
The request will go through just fine and the script will be inserted with the response to the request to "https://example.com" ... but if I try to make an explicit fetch request to the same URL I get a CORS error? Why is that happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您刚刚发明了JSONP:D
描述来自 w3school :
这是 stackoverflow
You just invented JSONP :D
Description from w3school:
Here is explanation on stackoverflow