-1

I got this error expecting $.ajax() to work in my contentScript

XMLHttpRequest cannot load http://example.com/tab/index.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'chrome-extension://gncbffieahbpgabchdjmhipkmahk****' is therefore not allowed access.

This is how the ajax look like in my contentscript.js

$.ajax({type: "GET",url: "http://example.com/tab/index.php", success: function(data){
    alert(data);
}});

and in my http://example.com/tab/index.html I already declared

header('Access-Control-Allow-Origin: *');

Any idea why it still doesn't work?

Aaron Musktin
  • 297
  • 3
  • 12

2 Answers2

0

This is most certainly not an issue on the extension side. It clearly says that the response does NOT contain the required header. You can confirm that in the Network tab of Dev Tools.

Look at your server-side code, but this question is unanswerable.

Unless, of course, you are willing to add your site to the permissions. Then CORS headers do not matter anymore.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • Not sure it's chrome problem, i installed this extension and it work https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi – Aaron Musktin May 28 '15 at 16:09
  • 1
    Which does the job for the server, intercepting the response before it reaches your extension. If it's a server you control, find out why the header is not sent. If it's a server you don't control, add the address to permissions. – Xan May 28 '15 at 16:19
0

It looks like the server doesn't allow Cross-Domain requests... Just try JSONP (there's an example here)

Community
  • 1
  • 1
0Bli0
  • 1
  • 2