我正在执行这段代码:
var element=null;
$.ajax({
type: 'GET',
async: false,
url: "C:\Users\myDir\Desktop\Project\jsonfile.json",
dataType: 'json',
success : function(data) {
element=data;
}
});
JSON 结构:
{
"info":[
{
"a1": "Ram",
"b1": "P123"
},
{
"a1": "ROM",
"b1": "P245"
}
]
}
但我在变量中什么也没得到
最佳答案
使用ajax检查是否有错误
var element=null;
$.ajax({
type: 'GET',
async: false,
url: "jsonfile.json",//Edited
dataType: 'json',
success : function(data) {
element=data;
}
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
关于javascript - 未从 JSON 文件获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16708000/