在启用Preflight request for request with keepalive specified is currently not supported
的情况下,使用获取API调用POST请求时出现错误keepalive
。任何帮助,将不胜感激 。我在beforeunload
事件中调用此api。
API请求
fetch(uri, {
method: 'POST',
headers: {
'Content-type': options.headers.get('content-type'),
'Authorization': options.headers.get('authorization')
},
body: JSON.stringify(interactionBody),
keepalive: true
}).catch((e) => {
console.log(e);
});
答案 0 :(得分:2)
我找到了一种解决方法,直到the Chrome issue fixed
使用mode: 'same-origin'
fetch(uri, {
method: 'POST',
headers: {
'Content-type': options.headers.get('content-type'),
'Authorization': options.headers.get('authorization')
},
body: JSON.stringify(interactionBody),
mode: 'same-origin',
keepalive: true
})