1

I'm writing a Chrome Extension that queries the API. Using jQuery, I have the following code called from my background page:

$.ajax({
    url: 'http://api.stackoverflow.com/0.8/questions/' + id
    , success: function(data, status, xhr) { console.log(data,status,xhr); }
    , dataType: 'json'
});

but I keep getting null for data, even though the call is successful (I have tried substituting id for a hard-coded, existing question id, so it's not the id). Using Chrome's (underpowered) console debugger, I discovered these request headers:

Accept:application/json, text/javascript, */*
Origin:chrome-extension://ogaegmflccigoelneakdpgbkccoakcbg
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.4 
(KHTML, like Gecko) Chrome/5.0.375.55 Safari/533.4

What am I doing wrong? If I can't make API calls from a Chrome Extension, then I've just wasted a few days of side-project programming time, which would suck...

1 Answer 1

6

Thanks for the help, S.Mark. Here's the answer:

http://code.google.com/chrome/extensions/xhr.html

You must register the API in your manifest.json file under permissions:

...
"permissions": ["http://api.stackoverflow.com/"],
...
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .