JavaScript无法向我的服务器发送GET请求

JavaScript无法向我的服务器发送GET请求,javascript,firefox-addon-webextensions,Javascript,Firefox Addon Webextensions,我有以下代码: function httpGetAsync(theUrl, callback) { var xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) callback(xmlHttp.responseText);

我有以下代码:

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:发生网络错误。


为什么会发生这种情况?如何解决此问题?

如果您正在开发浏览器扩展,请发送
获取
请求

转到您的
manifest.json
文件并添加
www.example.com
的权限:

{
    "name": "My extension",
    ...
    "permissions": [
        "http://www.example.com/*"
    ],
    ...
}
然后在您的背景页面(或其他地方)中,您可以执行以下操作:

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.example.com/test.php?foo=bar", false);
xhr.send();

var result = xhr.responseText;
参考


您提交请求的文件名是什么?它没有包含在URL路径中。@HamzaRashid
ŧest.php
是我提交请求的文件名。请确保您的文件在服务器上并且可以公开访问。@HamzaRashid是。我已经尝试使用浏览器手动发送请求,但效果很好。文件名
test.php
之间不应该有
/
。它应该是
http://myserver.com/test.php?u=test&p=testtest
很乐意帮助您。