The StackOverflow API uses JSONP:
All API responses are JSON, we do support JSONP with the jsonp query parameter.
(emphasis mine)
So you'll need to convert your AJAX call to use $.ajax
and properly populate the options to make the request:
$.ajax({
url: 'http://api.stackoverflow.com/1.1/questions',
dataType: 'jsonp', // let jQuery know this is a JSONP request.
jsonp: 'jsonp', // the callback parameter SO uses is called 'jsonp'
data: { // options that will get placed in the query string
pagesize: 20
},
success: function (data) {
$.each(data.questions, function (i, data) {
var question_list = '<li><a href="#">' + data.title + '</a></li>';
$(".questions").append(question_list);
})
}
});
Example: http://jsfiddle.net/QydkZ/1/
I tweaked the success callback to do something a little more readable, but the concept is the same.
As a side note, the version of the StackOverflow API you're using is deprecated. This is how you would write this against the 2.1 (current version) of the API:
$.ajax({
url: 'http://api.stackexchange.com/2.1/questions',
dataType: 'jsonp',
jsonp: 'jsonp',
data: {
pagesize: 20,
site: 'stackoverflow'
},
success: function (data) {
$.each(data.items, function (i, data) {
var question_list = '<li><a href="#">' + data.title + '</a></li>';
$(".questions").append(question_list);
})
}
});
Example: http://jsfiddle.net/k4AnW/1/
I'd highly recommend using the current version of the API instead.