duandange7480 2015-07-16 05:47
浏览 86

json_encode不起作用

I am using Jquery Flot Chart for plotting charts. To pass the data to chart,I am getting data from the database, and then I need to pass that php array into javascript array. I am using json_encode($array),but it is not working.

     $row=array();
      while($res=mysql_fetch_array($exequery))
     {
        $row[]=$res[0];
     }

Now,in the same file(without using ajax), I want to pass this php array to javascript array,which then will be used to plot chart.

    <script src="jquery-1.8.3.min.js"></script>
     <script src="jquer.flot.min.js"></script>     
     <script type ="text/javascript">
     var dataArray=<?php echo json_encode($row)?>;

When I am using this, chart is getting disappeared and alert(dataArray) is also showing nothing. Please help.

  • 写回答

1条回答 默认 最新

  • duanpu5048 2015-07-16 05:56
    关注

    Json parse using jquery:

    var dataArray=jQuery.parseJSON('<?php echo json_encode($row)?>');
    

    Open this link:- http://api.jquery.com/jquery.parsejson/

    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波