Search code examples
jqueryjsongetjsonp

Can't getJSON from 3rd party website


I want to get

https://www.g2a.com/lucene/search/quick?jsoncallback=jQuery1110048787688104918936_1507980736882&phrase=punch&isWholesale=false&cc=PL&skip=&start=0&rows=5&_=1507980736886

It’s a response on g2a for searching in a searchbox. I tried this:

$.ajax({
url: url,
type: "GET",
dataType: "jsonp",
success: function (data) {
    console.log(data);
}});

But I get an error:

jquery-3.2.1.min.js:4 Refused to load the script 'https://www.g2a.com/lucene/search/quick?jsoncallback=jQuery1110048787688104918936_1507980736882&phrase=s&isWholesale=false&cc=PL&skip=&start=0&rows=5&&callback=jQuery32104612888467884788_1507987847332&_=1507987847333' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".

As you can see it's a chrome extension, so it can’t have some PHP scripts, that can be found online.


Solution

  • you will have to add an entry for the server in your menifest.json, something like following-

    "content_security_policy": "script-src 'self' https://www.g2a.com; object-src 'self'"