在HTML文本字段中使用Ajax数据

时间:2018-07-16 13:38:30

标签: php html ajax

我有这个ajax脚本,它从ajax返回4个结果。我想在html中使用数据,以便我可以对其进行计算。

  <script type="text/javascript">
  $(document).on('change','.call_cal',function() {
    var date = $("#single_cal1").val();
    $.ajax({
      url: "wb_dnevni_pregled_ajax.php",
      type: "POST",
      data:  {date: date}, 
      dataType:'json',
      success: function(response) {
        $("#mybarChartOne").remove();
        $("#parent_canvas_one").html('<canvas id="mybarChartOne"></canvas>');

        var ctx = document.getElementById("mybarChartOne");

        var mybarChart1 = new Chart(ctx, {
          url:"wb_dnevni_pregled.php",
          type: 'bar',
          dataType:'json',
          data: {
            labels: ["Obrade", "Kontaktirani", "Zadržani","Terminirani"],
            datasets: [{
              label: "#",
              backgroundColor: "#26B99A",
              data: [response.first,response.second,response.third,response.fourth]
            }]
          },

          options: {
            scales: {
              yAxes: [{
                ticks: {
                  beginAtZero: true
                }
              }]
            }
          }
        });
      }
    });
  });
</script>   

我想在某些文本HTML字段中使用response.first数据,并且喜欢将response.first除以response.fourth

这是来自以下位置的返回数据:wb_dnevni_pregled_ajax.php

$total = array();
$total['first'] = $obrada_sql_list['total'];
$total['second'] = $kontakti_list['total'];
$total['third'] = $zadrzani_list['total'];
$total['fourth'] = $terminacije_list['total'];
print json_encode($total);

0 个答案:

没有答案