简体   繁体   English

json_encode不起作用

[英]json_encode is not working

I am using Jquery Flot Chart for plotting charts. 我正在使用Jquery Flot Chart绘制图表。 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. 要将数据传递到图表,我正在从数据库中获取数据,然后需要将该php数组传递到javascript数组。 I am using json_encode($array),but it is not working. 我正在使用json_encode($ array),但无法正常工作。

     $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. 现在,在同一文件中(不使用ajax),我想将此php数组传递给javascript数组,然后将其用于绘制图表。

    <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. 当我使用它时,图表消失了,alert(dataArray)也什么也没显示。 Please help. 请帮忙。

Json parse using jquery: Json使用jQuery解析:

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

Open this link:- http://api.jquery.com/jquery.parsejson/ 打开此链接: -http : //api.jquery.com/jquery.parsejson/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM