Javascript 未能执行';获取';在';窗口';无效模式
突然,浏览器中的所有提取请求抛出Javascript 未能执行';获取';在';窗口';无效模式,javascript,fetch,Javascript,Fetch,突然,浏览器中的所有提取请求抛出无法在“窗口”无效模式下执行“提取”。他们以前工作得很好。有人能给点提示吗?我的代码如下: function request(params) { let { api, method, data } = params let localParm = { method: method, mode: { mode: 'no-cors' }, credentials: 'include', headers: typeof H
无法在“窗口”无效模式下执行“提取”
。他们以前工作得很好。有人能给点提示吗?我的代码如下:
function request(params) {
let { api, method, data } = params
let localParm = {
method: method,
mode: { mode: 'no-cors' },
credentials: 'include',
headers: typeof Headers !== 'undefined' ? new Headers({ 'content-type': 'application/x-www-form-urlencoded' }) : { 'content-type': 'application/x-www-form-urlencoded' }
}
let url = apiNames[api] || api
if (method == "POST") {
localParm.body = toQueryString(data)
} else if (method == "GET") {
if (data) {
url += ("?" + toQueryString(data || {}))
}
}
const reqFunc = method === 'jsonp' ? fetchJsonp : fetch;
return reqFunc(url, localParm).then((response) => {
if (response.status === 200 || response.ok === true) {
try {
return response.json()
}catch(e){
console.log('11')
}
} else {
console.log('22')
}
}).then((res) => {
return res
})
}
从标题中删除CORS模式。您似乎开始在JavaScript规范中使用stage-0或stage-2。在该规范中,由于某种原因,fetch不允许CORS模式
let localParm = {
method: method,
mode: { mode: 'no-cors' },
credentials: 'include',
headers: typeof Headers !== 'undefined' ? new Headers({ 'content-type': 'application/x-www-form-urlencoded' }) : { 'content-type': 'application/x-www-form-urlencoded' }
}
应该像
let localParm = {
method: method,
credentials: 'include', ....
你在
22
:)之后缺少一个结束引号。我的错,实际代码与引号一起。最近更新后,我在Chrome和Firefox中的一个应用程序都出现了这种情况。但我使用的是Fetch规范中列出的凭据:“同源”
。用户报告了问题。检查以验证它是否正常工作,安装了Chrome更新,现在我每次都会遇到这个错误。对我来说,这似乎是一个浏览器错误。好吧,代码中的实际错误是由于模式:{mode:'no cors'}
,它写得不正确,正确的方法是模式:'no cors'