【发布时间】:2021-07-03 07:39:00
【问题描述】:
我在 JSON 中有这些数据:
{"minmax":["0.01","67.00"]}
我想使用 jQuery 来获取它,这就是我正在做的:
$.getJSON("../../dados/opcoesMinMax.json", function(data) {
var getMinMax = data;
});
// Need to use data here, out of the scope
我也尝试使用回调来做到这一点,这样做:
function getMinMax(callback) {
$.getJSON("../../dados/opcoesMinMax.json", function(data) {
callback(JSON.stringify(data));
});
}
// Need to use data here, out of the scope
即使使用回调,我也无法恢复数据。 console.log(getMinMax); 将函数返回给我。
console.log(getMinMax()); 返回我 undefined 并说 回调不是函数。
【问题讨论】:
标签: jquery json function callback