【发布时间】:2021-06-07 16:03:39
【问题描述】:
这令人困惑。
我在 Firefox 控制台中收到此错误:
Uncaught (in promise) TypeError: NetworkError when trying to fetch resource.
调用此函数时:
function sendMSG() {
let functionName = "getAllUsers"
let url = "https://api.kumulos.com/b2.2/asd/"+functionName+".json";
let username = 'asd';
let password = 'dsa';
let headers = new Headers();
headers.append('Content-Type', 'text/json');
headers.append('Authorization', 'Basic ' + username + ":" + password);
fetch(url,
{method:'POST',
headers: {
'Authorization': 'Basic ' + btoa(username+ ":" + password),
},
})
.then(response => response.json())
.then(json => console.log(json));
}
来自 HTML:
<button onclick="sendMSG()">Click me</button>
当我从代码本身调用此消息时,它可以完美运行,但是一旦我尝试单击,我就会收到上述错误。
在 Chrome 上我没有收到任何错误,但也没有结果。
这是我的错吗?
【问题讨论】:
-
可以检查cors
标签: javascript