我对jquery有点陌生。

我在jquery中有一个图,该图静态获取数据。

我要动态地

这是静态数据。

  var data = [
    { label: "New Request",  data: 1.7, color: "#68BC31"},
    { label: "On-Going",  data: 24.5, color: "#2091CF"},
    { label: "Deadlines",  data: 8.2, color: "red"},
  ]


我有一个ajax返回此值。

{“标签”:“活动”,“数据”:“ 4”,颜色:“#68BC31”}

这是我的ajax。

jQuery.ajax({
  type: "POST",
  url: "dashboard/graph_data/",
  success:function(response){

     return response;

     // the response returns this value

     // {"label":"active","data":"4", color: "#68BC31"}

  }
});


如何将静态数据替换或转换为我的Ajax函数。

提前致谢

最佳答案

var data = [
    { label: "New Request",  data: 1.7, color: "#68BC31"},
    { label: "On-Going",  data: 24.5, color: "#2091CF"},
    { label: "Deadlines",  data: 8.2, color: "red"},
  ];

jQuery.ajax({
  type: "POST", // Are you sure you want POST and not GET ?
  url: "dashboard/graph_data/",
  dataType: "json", // If you know the return value type, explicitely type it

  success: function(response){
     data.push(response); // Maybe you'll need to JSON.parse() the response, but not sure
     console.log(data); // Your data array has been updated asynchronously
  }
});

10-04 10:58
查看更多