Как загрузить загрузку с помощью AJAX, не включая все файлы PHP - PullRequest
0 голосов
/ 12 февраля 2019

У меня проблема, когда я загружаю страницу с помощью .laod () или $ .ajax (), она загружает только контент, такой как статическая страница

на page1.php, у меня есть функция getStats () как php, и яиметь <div id="loadpage">

и на page2.php я при использовании getStats () и page2.php загружаю в <div id="loadpage">

, поэтому я включил все нужные мне файлы вpage2.php, но запуск стал слишком медленным

, поэтому я попытался загрузить страницу с включением, и когда флажок был установлен, он снова загрузит содержимое, как

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

, но вы можете представить, что яполучить, когда у моей page2.php есть таблица с 300 строками данных

, поэтому я отказываюсь от этого решения

и мой план каждый раз, когда я ставлю галочку, он сбрасывает мою таблицу

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

код активации: // загружается, но очень медленно

[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 ..

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...