Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

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...

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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/"],
...
}
share|improve this answer
    
+1, great, thanks for the info, @Jason. –  YOU May 26 '10 at 7:05
add comment

You must log in to answer this question.

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