doulao7998636570 2016-08-03 10:55
浏览 46
已采纳

PHP到Javascript传递变量返回null结果

Here is the code that I have:

https://jsfiddle.net/a6kukf3n/

The PHP variable $weekParses contains the following data:

WK 14,WK 15,WK 16,WK 17,WK 18,WK 19,WK 20,WK 21,WK 22,WK 23,WK 24,WK 25,WK 26,WK 27,WK 28,WK 29,WK 30,WK 31,

However, when I add it to the var weekCases on Javascript and try to print it to the console or my charts.js file it returns null, 1, 2 ,3 ,4 etc

What am I doing wrong? How do I send my PHP variable to JS?

  • 写回答

2条回答 默认 最新

  • dtdd25012 2016-08-03 11:03
    关注

    Please create a new array in php and assign the value to array

    $data_week=array();
    
    while ($weeks = mysqli_fetch_row($numRowsQuery))
        {
    
          $data_week[]=$weeks
    
        }
    

    After that please try

    <script type="text/javascript">  
        //pass php variable to js for open cases pw
        <?php $weekParse = $data_week; ?>
        var weekCases = <?php echo json_encode($weekParse); ?>; 
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度