$.ajax({url:"http://api.duoshuo.com/threads/counts.json?short_name=official&threads=4ff1cbc43ae636b72a00001d",dataType:"jsonp"}).done(function(data){console.log('done');});如果把dataType改成JSON,則會(huì)出現(xiàn)錯(cuò)誤No'Access-Control-Allow-Origin'headerispresentontherequestedresource.Origin'http://localhost:4000'isthereforenotallowedaccess.應(yīng)該是無(wú)法跨域。按理來(lái)說(shuō)處理成功會(huì)在console顯示'done',但是返回錯(cuò)誤'UncaughtSyntaxError:Unexpectedtoken:'這是多說(shuō)的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":"暫無(wú)","comments_one":"1條評(píng)論","comments_multiple":"{num}條評(píng)論"},"code":0}似乎應(yīng)該是能通過(guò)JSON校驗(yàn)的。如果沒(méi)有辦法,如何獲取這個(gè)JSON當(dāng)中'comments'的值呢?(在這個(gè)api里comments=145)
處理 JSON 出現(xiàn)錯(cuò)誤Uncaught SyntaxError: Unexpected token :
明月笑刀無(wú)情
2019-03-29 22:08:09