我發現了問題,但是我的解決方案不起作用。變量d0和d1被填充,但在代碼創建並拼接數組storelocations之後。因此,我得到一個錯誤,d0和d1未定義。任何解決方案JSON javascript未定義變量問題
的Javascript:
$(function() {
$.get("/Map/GetJsonData", function (data) {
storeLocations = [];
var d0 = data[0].Delay;
var d1 = data[1].Delay;
});
var storeLocations = new Array();
storeLocations.splice(storeLocations.length, 0, d0);
storeLocations.splice(storeLocations.length - 1, 0, d1);
}
是不是在外部功能舉行的範圍? – Zlatko