伊夫包括我下面的腳本,在那裏我試圖把一個JSON文件到使用Ajax回調函數一個網站的最末端。當我檢查頁面時,我看到JSON文件格式不正確,我似乎無法找到答案。該網頁還顯示JSON文件是「未定義的」。建議感激!GeoJSON的「不規範」,在控制檯消息,並出現未定義
function debugCallback(response){
var mydata;
$("#mydiv").append('GeoJSON data: ' + JSON.stringify(mydata));
};
function debugAjax(){
var mydata;
$.ajax("data/MegaCities.GeoJSON", {
dataType: "json",
success: function(response){
//mydata = response;
debugCallback(mydata);
}
});
$("#mydiv").append('<br>GeoJSON data:<br>' + JSON.stringify(mydata));
};
//$("#mydiv").append('GeoJSON data: ' + JSON.stringify(mydata));
if(typeof mydata === 'undefined') {
console.log("undefined data")
} else {
console.log("not undefined")
}
$(document).ready(debugAjax());
$ .getJSON()試試這個和http://api.jquery.com/jquery.getjson/ –