关于加载函数和 json 的问题

Question about load function and json

本文关键字:json 问题 函数 于加载 加载      更新时间:2023-09-26

可以做这样的东西吗?

$.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'
});