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.
    评论

报告相同问题?