$.ajax({
url: "http://api.duoshuo.com/threads/counts.json?short_name=official&threads=4ff1cbc43ae636b72a00001d",
dataType: "jsonp"
}).done(function(data) {
console.log('done');
});
如果把 dataType 改成 JSON ,则会出现错误No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4000' is therefore not allowed access.
应该是无法跨域。
按理来说处理成功会在 console 显示'done',但是返回错误'Uncaught SyntaxError: Unexpected token :'
这是多说的 api ,地址显示如下:{"response":{"4ff1cbc43ae636b72a00001d":{"thread_id":"1152923703633758877","channel_key":null,"thread_key":"4ff1cbc43ae636b72a00001d","comments":145,"reposts":0,"likes":28,"weibo_reposts":13,"qqt_reposts":7}},"options":{"comments_zero":"暂无","comments_one":"1条评论","comments_multiple":"{num}条评论"},"code":0}
似乎应该是能通过 JSON 校验的。如果没有办法,如何获取这个JSON 当中'comments'的值呢?(在这个 api 里 comments = 145)
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
JSONP≠JSON!