无论如何,有没有更新HTML内定义的现有数组?

时间:2019-03-25 05:01:03

标签: javascript jquery html arrays ajax

有一个静态数组,应该根据click事件动态更新。

我能够使用Ajax以数组格式获取动态值,但是很难将其设置为现有变量。

Ajax返回以下数组

echo json_encode($arry);
// ["2","1","1","0","1","0"]
$.post( "ajaxcall.php", { ids: id })
   .done(function( returnedArray){
      //returnedArray looks like ["2","1","1","0","1","0"]
      datasets: [{
                  //data: [10,12,33,50,12,34]
                  data: returnedArray
                 }]
     },

但是在单击事件之后,不会解释returnArray来放置值。

基本上,结果应如下所示:

data: ["2","1","1","0","1","0"]

1 个答案:

答案 0 :(得分:1)

使用赋值运算符代替:

datasets = [{
     //data: [10,12,33,50,12,34]
     data: returnedArray
}]