![](/img/trans.png)
[英]'Uncaught SyntaxError: Unexpected token :' when parsing valid JSON
[英]Uncaught SyntaxError: Unexpected token : for a valid JSON
我試圖通過$ .ajax方法獲取跨域JSON數據
$.ajax({
type: "GET",
dataType: 'jsonp',
url: "http://nrb.org.np/exportForexJSON.php?YY=2016&MM=06",
crossDomain : true,
})
.done(function( data ) {
console.log("done");
console.log(data);
})
.fail( function(xhr, textStatus, errorThrown) {
console.log(xhr);
console.log(xhr.responseText);
// alert(xhr.responseText);
// alert(textStatus);
});
url返回的JSON是
{
"Conversion": {
"Currency": [{
"Date": "2016-06-23",
"BaseCurrency": "INR",
"TargetCurrency": "NPR",
"BaseValue": "100",
"TargetBuy": "160.00",
"TargetSell": "160.15"
}, {
"Date": "2016-06-23",
"BaseCurrency": "USD",
"TargetCurrency": "NPR",
"BaseValue": "1",
"TargetBuy": "107.76",
"TargetSell": "108.36"
}, {
"Date": "2016-06-23",
"BaseCurrency": "BHD",
"TargetCurrency": "NPR",
"BaseValue": "1",
"TargetBuy": "285.75",
"TargetSell": "N/A"
}]
}
}
我使用http://jsonlint.com/檢查了JSON是否有效。 JSON是好的。 我收到控制台錯誤。
Uncaught SyntaxError: Unexpected token :
控制台指向以下屏幕截圖中的錯誤
嘗試將dataType
更改為"json"
自動評估javascript內容類型的響應。 JavaScript JSON解析器將{和}視為塊而不是對象。
為JSON文件設置正確的Content-Type標頭。 或者用.json擴展名保存。
您的網址有.json擴展名,而標題是jsonp ,請嘗試使其相同
不太確定POST和JSONP:將數據發布到JsonP
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.