工作,我想讀的使用jQuery的方法的getJSON本地JSON文件,所以我寫下面的代碼來讀取,但控制檯日誌在Firefox工作正常,並顯示輸出,但在Chrome中不工作。 對鉻我得到這個錯誤:的Jquery的getJSON無法在Chrome
Request Failed: parsererror, SyntaxError: Unexpected token } in JSON at position 951
這裏是我寫的代碼:
$(document).ready(function(){
$.getJSON('http://localhost/page2/data/cd.json',function(data){
alert("success");
console.log(data);
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.log("Request Failed: " + err);
});
});
我主持的XAMPP本地服務器, 我還要檢查JSON文件驗證此文件。 該文件是有效的JSON文件。
你能確認你的JSON是一個有效的像'{「鍵」:「值」}' – Jai
我不知道,你是如何驗證你的JSON,但你可以請檢查它在HTTP ://jsonlint.com/ – agpt
是文件vaildate使用jsonlint.com –