donglunzai4288 2012-07-31 06:39
浏览 28

用javascript函数初始化php变量[关闭]

hi i want to initialize php variable in javascript function and than call the php function with php initialized variable. Please help me for solving this problem...

    <?php
    function printDiv($abc) {
        echo '<div align="center" width="100%"> ' . $abc . ' </div>';
    }
    ?>
    <script type="text/javascript">
        function callPhpFunction(jsabc) {
            <?php $abc ?> = jsabc;
            document.write("<?php printDiv($abc) ?>");
        }
    </script>
  • 写回答

1条回答 默认 最新

  • douguaidian8021 2012-07-31 06:42
    关注

    Unfortunately it cannot be done the way you are describing. Javascript is a client side scripting and PHP is a server side scripting language. You will need to look into ajax calls to fill the javascript variables.

    Order of Operations (bare-bones):

    1. Server gets request for page
    2. Server parses PHP, or other language, to send page to browser
    3. Client recieves page from server
    4. Loads any additional files/scripts needed - Restarts at step 1 for any new requests
    5. Executes Javascript (Normally as it is loaded unless using jQuery $().ready then after document has loaded.
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭