如何在不包含所有php文件的情况下使用ajax加载负载

时间:2019-02-12 16:29:24

标签: javascript php jquery html ajax

我用.laod()或$ .ajax()加载页面时遇到问题 它只加载静态页面之类的内容

在page1.php中,我具有函数getStats()作为php,并且我具有<div id="loadpage">

在page2.php上,使用getStats()和page2.php时,我在<div id="loadpage">

中加载了

所以我已经在page2.php包含了我需要的所有文件,但是开始变得太慢了

所以我尝试加载带有include的页面,当选中任何复选框时,它将再次加载内容,如

$("#loadpage").text("<?php include "page2.php"?>");

但是您可以想象,当我的page2.php包含一个包含300行数据的表时,我会得到什么

所以我放弃了这个解决方案

我的计划是每次我选中一个复选框都会重置我的桌子

$func=getStats($_POST['statut']);
<div id="loadpage">
echo "$func";
</div>

actuel代码://加载但速度很慢

[page1.php]

<div id="loadpage">
</div>
<script type="text/javascript">
  $(function(){  
    $("#loadpage").load("views/suivicommande2View.php",{"statut" : "","page":"page2.php"});


    $("input[type='checkbox']").change(function(){
      var statut = [];
      $.each($(".ckb:checked"), function(){
        statut.push($(this).val());
      });

      console.log(statut);
      var urgent = $("input[name='Urgent']").val();
      console.log(urgent);

      $("#loadpage").load("views/page2.php",{"statut" : statut,"page":"suivicommande2View.php"});
    });

  });

</script>

[page2.php]

<?php include "function.php" ?>
<table id="myTable" class="table table-bordered display" style="width:100%">
      <thead>
        <tr>
         <th> some th here</th>
        </tr>
      </thead>
      <tbody >
      <?php
        $data=getStats($_REQUEST['statut']); //getStats function is in function.php
        //getStats([statut]){ return data } 
        // var_dump($historiques);
        foreach ($data as $oneData) {
        //showing all my data as table
        }
      </tbody>
</table>

[function.php]

function getStats($condition = null,$date=null,$type=null,$hide_col=false){
  //setting default val
  if($condition == null)$condition = null;
  if($data == null)$date="DESC";
  if($type == null) $type=null;
  if($hide_col==0)$hide_col=" AND hide_col IS NULL";else {
    $hide_col="";
  }

  $where=where($condition);
  $where2=where2($type);
  if(!$date === null){
    $ordre =" ORDER BY `wor7576_historique_commandes`.id_commande".$date;
  }else {
    $date ="";
  }

  $req="SELECT distinct * FROM `wor7576_historique_commandes` where ".$where2." AND ".$where."  ".$hide_col." ".$ordre;

  // echo $req ; // show query req


  $db=DBConnect();
  $mysqli_request = mysqli_query($db, $req);

  $res=array();
  $result_request = mysqli_fetch_all($mysqli_request, MYSQLI_ASSOC);

  return $result_request;
}

function where($condition){
  if(!count($condition)==0){
    $where =" ( ";
    for ($i=0; $i < count($condition); $i++) {
      $where= $where." statut = ".$condition[$i];
      if( $i ==(count($condition)-1) ){
      }else{
        $where= $where ." OR ";
      }
    }
    $where =$where .")";
  }else {
    $where =" (statut = statut) ";
  }
  return $where;

}

function where2($type){
  if(!count($type)==0){
    $where2 =" ( ";
    for ($i=0; $i < count($type); $i++) {
      $where2 = $where2." type = '".$type[$i];
      if( $i ==(count($type)-1) ){
      }else{
        $where2 = $where2 ."' OR '";
      }
    }
    $where2 = $where2 ."')";
  }else {
    $where2 ="(type = type)";
  }

  return $where2;
}

我只是在互联网上学习jq和ajax大约1周
我不确定即时通讯是否以正确的方式使用.load或ajax。

0 个答案:

没有答案