little-dude
little-dude

Reputation: 1674

XMLHttpRequest is not defined, in a chrome extension options page

I'm trying to make an XMLHttpRequest in the options page of an extension. In my options.js file I simply have the following code :

if (window.XMLHttpRequest){
        var xhr = new getXMLHttpRequest();
}

But I have this error in the console

Uncaught ReferenceError: getXMLHttpRequest is not defined

I saw here that getXMLHttpRequests are a problem for hosted apps, but in this case, it's a simple extension, so I don't understand.

Upvotes: 7

Views: 20620

Answers (2)

PAT
PAT

Reputation: 1

You can use

function GetXmlHttpObject()
{ 
    var objXMLHttp=null;
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}

Upvotes: -2

Quentin
Quentin

Reputation: 943556

To construct an XHR object you use new XMLHttpRequest();.

getXMLHttpRequest is not a standard function.

I saw here that getXMLHttpRequests are a problem…

The question at the other end of the link doesn't use a function with a name starting with get.

Upvotes: 5

Related Questions