gpt4 book ai didi

javascript - NodeWebkit 中的 XMLHttpRequest,状态 = 0

转载 作者:行者123 更新时间:2023-11-29 15:41:28 25 4
gpt4 key购买 nike

在我的本地服务器上执行此操作时,这在 Chrome 中有效。但是,当我转移到 NodeWebkit 时,它失败了,状态 === 0。

function ReadText(filename) {
var txtFile = new XMLHttpRequest();
txtFile.open("GET", filename, true);
txtFile.onreadystatechange = function () {
if (txtFile.readyState === 4) // Makes sure the document is ready to parse.
{
if (txtFile.status === 200) // Makes sure it's found the file.
{
g_FileLoadContents = txtFile.responseText;
ReadFile();
}
}
}
txtFile.send(null);
};

g_FileLoadContents 是一个全局函数,而 ReadFile 是一个在 g_FileLoadContents 上做一些工作的函数......但它在 NodeWebkit 中并没有那么远(我再次强调,当在我的本地服务器上时,Chrome 在 Chrome 中一切正常)。

在 NodeWebkit 中,我看到 txtFile.readyState 变为 4,但随后 txtFile.status 变为 0。

为什么状态为0?当我使用 nodeWebkit 时,我是否应该在上面的代码中让状态为 0?

我很困惑,希望有人能解释一下。

最佳答案

HTTP 状态代码由网络服务器返回。据推测,当您在 Chrome 中执行此操作时,您的本地服务器返回 200,但 node-webkit 仅返回 0(Unknown?)。

但通常读取本地文件是受限的。上面的代码是否实际生成了文件内容?即便如此,如果您尝试读取 node-webkit 中的文件,我建议您使用 node fs module直接访问文件系统。

关于javascript - NodeWebkit 中的 XMLHttpRequest,状态 = 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18391481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com