简体   繁体   中英

json_encode is not working

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.

Json parse using jquery:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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