【发布时间】:2022-09-27 20:42:04
【问题描述】:
我有一个带有 javascript 的网页,它将 json 数据发布到 python 烧瓶应用程序。 在 Chrome、Edge、Opera、Android、a.s.o 上一切正常。 只是 Firefox 给了我一个错误。
这是我的 JavaScript:
const xhr = new XMLHttpRequest();
xhr.open(\"POST\", url);
xhr.setRequestHeader(\"Content-Type\", \"application/json;charset=UTF-8\");
xhr.setRequestHeader(\"Authorization\", authdata);
xhr.onreadystatechange = function(ev) {
//2 - request sent, 3 - something back, 4 - full response
//console.log(xhr.readyState);
if (xhr.readyState === 4) {
switch (xhr.status) {
case 200:
case 304:
console.log(\"OK or Not Modified (cached)\", xhr.status);
console.log(xhr.responseText);
break;
case 201:
console.log(\"Created\", xhr.status);
console.log(xhr.responseText);
break;
case 400:
console.log(\"Bad Request\", xhr.status);
alert(\"Bad Request\");
break;
case 401:
case 403:
console.log(\"Not Authorized or Forbidden\", xhr.status);
alert(\"Not Authorized or Forbidden\");
break;
case 404:
console.log(\"Not Found\", xhr.status);
alert(\"404 Not Found\");
break;
case 500:
console.log(\"Server Side Error\", xhr.status);
alert(\"Server Error 01 Code: \" + xhr.status.toString());
break;
default:
console.log(\"Some other code: \", xhr.status);
alert(\"Server Error 02 Code: \" + xhr.status.toString());
}
}
};
xhr.onerror = function(err) {
console.warn(err);
alert(\"Server Error 99\", err);
};
edata = JSON.stringify({ \"domain\": \"workdomain\", \"zonedata\": \"data\" });
xhr.send(edata);
当我在 Firefox 中触发它时,我得到一个 \"Server Error 02\" 状态代码 0 如果我查看调试器网络选项卡,则没有 POST 发送。
这是火狐的问题吗?
-
\"这是 Firefox 的问题吗?\"- 在 2022 年仍然使用 XMLHttpRequest 而不是
fetch,这可能是您在开发人员方面可以称之为问题的问题 :-) -
不确定这是否是 Firefox 问题 - 我从未见过错误代码 02 - 哦,等等,那是您的代码在执行此操作...
-
developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status:\"如果出现 XMLHttpRequest 错误,浏览器也会报告状态为 0。\"- 您在浏览器控制台中遇到任何其他错误?这是跨域/受CORS影响吗?
-
是
urlhttp://.....? https://....?别的东西? -
没有其他错误。网址是10.10.0.43:5555/someroute。 CORS 不是问题。所有其他浏览器都成功发送帖子。
标签: javascript firefox