首页 > 解决方案 > 如何在 JavaScript 代码中加载 PHP 文件?

问题描述

您好,我有一个名为 test.php 的 PHP 文件。为此,我有以下代码:

  <body>
            function writeData(){
              
              firebase.database().ref("User").set({
              name: document.getElementById("nameField").value,
              age: document.getElementById("ageField")
              });

              ***Here the test.php file should be reloaded***
              }
              
            </script>
                <div class="box">
<center>            <div class="button">
                    
                        <button onclick = "writeData()"> Submit </button>

                    </div>
                </div>
</center>

 </body>

如何在 Javascript 代码中重新加载我的 test.php 文件?我会很高兴得到答案

标签: javascriptphpreload

解决方案


刷新


 location.reload();

如果你想在不刷新的情况下加载文件,你应该使用 Ajax

使用 jquery 的工作流示例


$('#yourdiv_id').load('page.php');


推荐阅读