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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line