douduanque5850 2016-10-09 17:51
浏览 539
已采纳

如何在所有页面中更新包含php而不刷新

I need update only a part of the page where its included an include php with a specific path. How update only this file included with this include.

Code is this:

<tbody>
   <?php include_once "tabelas/table.php";  ?>
</tbody>

What I am doing in really is calling a function javascript that do update and it do update, but it not do update in this include php. Thanks advance!

(i dont want do require in ajax because it is a datatable and in this case it just work with include php, so i need a solution in php preferenly)

  • 写回答

2条回答 默认 最新

  • duanlongling5308 2016-10-09 18:09
    关注

    You cannot update only part of a page with PHP without using AJAX. The Javascript AJAX call will run a PHP script that can access the database using PHP and will return the results.

    You will need a Javascript function to make the AJAX call:

    <script>
    function jsupdate(returnid) {
     xmlhttp=new XMLHttpRequest();
     xmlhttp.onreadystatechange=function()  {
     if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById(returnid).innerHTML=xmlhttp.responseText;
     }
    }
    xmlhttp.open("GET","databasecall.php,true);
    xmlhttp.send();
    

    }

    Then you will need a PHP script called "databasecall.php that accesses the database, so would contain something like:

    //first include your database connection
    
     $sql = "SELECT * from mytable limit 1 ";
     $result = mysql_query($sql) or die ('Error: XXX000');
     if (mysql_num_rows($result) > 0) {
      $row = mysql_fetch_array($result);
      echo $row[0];
     }
     else {
       echo 'No such database table entry';
     }
    

    The echo-ed results are returned to the Javascript.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建