zoukankan      html  css  js  c++  java
  • PHP和Javascript传递数组参数的方法

    <?php
        include_once("./class.config.php");

        $Result = $db->SelectSQL("select * from dept order by ParentDeptCode");

        while($temp = $db->Fetch($Result))
        {
            $Rs[]=$temp;
        }
        //如果PHP版本为5.2.0以上,直接用内置JSON函数
        //否则就使用第3方的JSON类库
        $str=json_encode($Rs);
        /*
        下面是调用js的方法
        注意:下面的写法是错误的:
        //echo '<script type="text/javascript">Test("'.$str.'");</script>';
        echo '<script type="text/javascript">Test('.$str.');</script>';
        */
    ?>

    <script type="text/javascript">
    //如果是AJAX,则使用responseText来接受数据
    //注意你估计要用arr = eval("("+X.responseText+")");
        var r=eval(<?=$str?>);
        for(i=0;i<r.length;i++)
        {
            document.write('部门:'+r[i].DeptCode+'=>'+r[i].DeptName+'<br>');
        }
    </script>

  • 相关阅读:
    Binary Tree Paths
    Implement Stack using Queues
    Path Sum II
    Path Sum
    Plus One
    Add Digits
    Missing Number
    H-Index II
    H-Index
    Ugly Number II
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/1498394.html
Copyright © 2011-2022 走看看