可以做出这样的东西吗?
$.ajax({
url: "test.php",
success: function(json, json1){ //Question here, can i have more than one?
$m0 = [];
$m0.push(parseFloat(json));
alert($m0); //show 750
$m1 = [];
$m1.push(parseFloat(json1));
alert($m1); // show 320
}
});
json 中的预期返回值是什么?
例如这个? [750, 320]
还是这个 [750] [320]?
最佳答案
我认为这是不可能的; JSON 通常仅包含一个顶级值。标准方法是让 test.php
返回一个包含两个值的 JSON 数组:
[750, 320]
您的加载函数将如下所示:
$.ajax({
url: "test.php",
success: function(json){
$m0 = [];
$m0.push(parseFloat(json[0]));
$m1 = [];
$m1.push(parseFloat(json[1]));
},
// this will ask jQuery to parse the JSON for you;
// otherwise, your success function will receive the
// string "[750, 320]" as the argument
dataType: 'json'
});
关于javascript - 关于load函数和json的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6051943/