2
votes

I have a Chrome Content Script and I want to POST data to a remote server using AJAX

    $.ajax({
          url: "http://remote_server/endpoint.php",  
          type: "POST",  
          dataType: "json",  
          contentType: "json",  
          data: {"foo": "bar"},
    });

I can post it to my locally hosted server if I set the following in manifest.json -

  "permissions": [
    "http://*/"
  ],

or

  "permissions": [
    "http://localhost/"
  ],

However I get an error if try and post the data to a remote server, even when I have either of the following settings in manifest.json -

  "permissions": [
    "http://*/"
  ],

or

  "permissions": [
    "http://remote_server/"
  ],

I thought if you set the permissions you are allowed to make cross-site requests? So why is this not working?

XMLHttpRequest cannot load http://remote_server/endpoint.php. Origin chrome-extension://koogajpmmcapakdeahannaecjbcfgicl is not allowed by Access-Control-Allow-Origin.

1

1 Answers

1
votes

It should work. Make sure that after making your changes you are reloading the extension: Settings->Tools->Extensions and clicking the 'Reload' link for your extension.