Ryan
Ryan

Reputation: 10049

Javascript, Chrome Extension development, XMLHttpRequest Access-Control-Allow-Origin problem

Am having a slightly confusing problem with this extension (although it might just be my inexperience) in my manifest file I have:

"permissions": [
    "http://mafre.com/","http://eee.se/","http://ilaafire.net/","notifications","tabs"

And i am using this code to send an XML request:

var http = false;
    http = new XMLHttpRequest();

function replace() 
{


            http.open("GET", "http://www.mafre.com/proj/test.php"+getquerystring(), true);
            http.onreadystatechange=function() 
            {

            if(http.readyState < 4) {show_wait_gif();}
                else if(http.readyState == 4) 
                {
                    updatepage( http.responseText);

                }
            }
          http.send(null);
 }

which my script on the other end is getting the data... but when I need to get the response Chrome is throwing this error:

XMLHttpRequest cannot load http://www.mafre.com/proj/[email protected]. Origin 
chrome-extension://kjggpdimdloblnddfbnodggchjpalihb is not allowed by Access-Control-Allow-Origin.

Why is that? I have already given it permission to interact with the domain so why cannot I get the response even though it is sending the query?

The response that I should get back into my page is something like "email accepted, thanks!1"

Thanks!

Upvotes: 1

Views: 1461

Answers (1)

pimvdb
pimvdb

Reputation: 154958

I believe you should wildcard permission URLs, also www. is a different domain:

"http://mafre.com/*",
"http://www.mafre.com/*",

"http://eee.se/*",
"http://www.eee.se/*",

"http://ilaafire.net/*",
"http://www.ilaafire.net/*",

"notifications",
"tabs"

Currently you only have access to exactly http://mafre.com/.

Upvotes: 6

Related Questions