Dhaivat Pandya
Dhaivat Pandya

Reputation: 6536

Chrome Extension, Jquery ajax failed

I'm trying to write myself a chrome extension, and I have the following lines in it that seem to be failing:

fk_url = "http://www.flipkart.com/search-books?query=" + search + "algorithms&from=all";
$.get(fk_url);

And, when my extension is run, it gives me this error:

XMLHttpRequest cannot load http://www.flipkart.com/search-books?query=algorithmsalgorithms&from=all. Origin chrome-extension://cpepfejkgdnhemablbikonijfjnjmnha is not allowed by Access-Control-Allow-Origin.

I'm totally lost as to how I can fix this. Any help? (The website I'm trying to connect to does not offer an API)

Upvotes: 0

Views: 984

Answers (2)

RwwL
RwwL

Reputation: 3308

If they don't offer an API, you're pretty much out of luck with a Chrome extension, I'm afraid. You can't just AJAX-request any resources from any domain (unless they allow you access: https://developer.mozilla.org/en/http_access_control).

For more details, read http://en.wikipedia.org/wiki/Same_origin_policy

Upvotes: 0

Jimmy Sawczuk
Jimmy Sawczuk

Reputation: 13614

Your manifest.json file should have the domain you're looking to use in the permissions:

"permissions": [
    "http://*.flipkart.com/"
]

Upvotes: 2

Related Questions