1

I have this code:

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");

when I try to run it on Firefox's console, I get:

NetworkError: A network error occurred.

Why does this happen? How can I fix this?

WayneXMayersX
  • 338
  • 2
  • 10

1 Answers1

2

Sending GET request if you are developing a browser extension

Go to your manifest.json file and add permission for www.example.com:

{
    "name": "My extension",
    ...
    "permissions": [
        "http://www.example.com/*"
    ],
    ...
}

Then in your background page (or somewhere else) you can do:

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

var result = xhr.responseText;

Reference

How do I send an HTTP GET request in chrome extension?

Community
  • 1
  • 1
Hamza Rashid
  • 1,329
  • 15
  • 22