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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?