我正在尝试使用以下jQuery代码向Stack Exchange API 发送请求:
$.ajax({
type: 'POST',
url: 'http://api.stackoverflow.com/1.1/stats',
dataType: 'jsonp',
success: function() { console.log('Success!'); },
error: function() { console.log('Uh Oh!'); }
});
但是当我在我的机器上用FireFox或Chrome打开文件并发出请求时,我会收到这个错误:
Resource interpreted as Script but transferred with MIME type application/json.
Uncaught SyntaxError: Unexpected token :
Uh Oh!
我不知道发生了什么事。我知道Stack Exchange API会对其响应进行Gzip压缩,这会导致任何问题吗?
XMLHttpRequest cannot load http://api.stackoverflow.com/1.1/stats. Origin null is not allowed by Access-Control-Allow-Origin.
- theabraham