【发布时间】:2023-04-05 01:43:01
【问题描述】:
我有这个代码:
function httpGetAsync(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
httpGetAsync("http://myserver.com/test.php/?u=test&p=testtest");
当我尝试在 Firefox 的控制台上运行它时,我得到:
NetworkError: A network error occurred.
为什么会这样?我该如何解决这个问题?
【问题讨论】:
-
您提交请求的文件名是什么?它不包含在 URL 路径中。
-
@HamzaRashid
ŧest.php是我提交请求的文件名。 -
确保您的文件存在于服务器上并且可以公开访问。
-
@HamzaRashid 是。我已经尝试使用浏览器手动发送请求,并且效果很好。
-
文件名
test.php和?之间不应有/。应该是http://myserver.com/test.php?u=test&p=testtest
标签: javascript firefox-addon-webextensions