1

I am using cross domain data calls in my chrome extension. I have created a PHP function to make use of an API. So I'm making a call to this function using JSONP and expecting to get the values in return. But this is the error I'm getting in the console.

Can anyone help me with this. What is the problem here? What do I have to do? I do not have any experience with chrome extensions.

In my situation I think that only YouTube is blocking the content because it is expecting the cross domain connections to be HTTPS. So it's not allowing the cross domain calls. Well that's what I think. But if that problem can be solved using a background script. Can you please help with how to proceed?

Anonymous
  • 145
  • 1
  • 4
  • 14
  • 1
    Possible duplicate of [Cross-domain XMLHttpRequest using background pages](http://stackoverflow.com/questions/7699615/cross-domain-xmlhttprequest-using-background-pages) – wOxxOm Nov 27 '15 at 11:48
  • In short: XHR/AJAX in content scripts will fail if the page is served with a Content Security Policy header with a restricting `connect-src`. Also note that in `"http://*/"` the `*` means any *host* but not any *path*, should be `"http://*/*"` or better `"http://192.168.40.141/*"` – wOxxOm Nov 27 '15 at 11:48
  • Yes I already checked [that page](http://stackoverflow.com/questions/7699615/cross-domain-xmlhttprequest-using-background-pages) so do I need to have a background script. But how should I use it. That page didn't make it clear for my situation. Because in my case YouTube is blocking the content as it is over HTTPS and mine is on HTTP. Well I guess so. – Anonymous Nov 27 '15 at 11:59
  • 1
    That page describes everything you need in detail. What exactly is unclear? – wOxxOm Nov 27 '15 at 12:00
  • @AkashKumar — So stop serving your script over HTTP without SSL. – Quentin Nov 27 '15 at 12:10
  • Use https version for the request. This may be helpful - http://stackoverflow.com/questions/7699615/cross-domain-xmlhttprequest-using-background-pages/7699773#7699773][1] – Antony Joslin May 12 '17 at 11:17

1 Answers1

1

I get the same problem like yours, and, I just change my AJAX URL to HTTPS, like this:

My old URL is

var url="http://fanyi.youdao.com/openapi.do?keyfrom=fgbnbb&key=1276642867&type=data&doctype=json&version=1.1&q="+txt;

And then, I change it to var url="https://fanyi.youdao.com/openapi.do?keyfrom=fgbnbb&key=1276642867&type=data&doctype=json&version=1.1&q="+txt;, and then, the problem is gone.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275