title: how to save a table in xhr.responseText
body: <p>I've been trying to do a fast research with Ajax and i want to get a html table inside a xhr.responseText to next get a new research result and i was doing this but i didn't find a way to do it can u please help me resolving it if possible ? </p>
  
  <p>Javascript Function </p>
  
  <pre><code>  function changement(str) {
  
          xhr = new XMLHttpRequest(); 
           var input = document.getElementById('rech').value;
  
          xhr.open('GET','?controller=livres&amp;action=search&amp;val=1316', true);      
          xhr.send();
          xhr.onreadystatechange = function () {
              if (xhr.readyState == 4 &amp;&amp; xhr.status == 200) {
                  document.getElementById("tab").innerHTML = xhr.responseText;
                  alert(xhr.responseText);
              }
  
          };          
  
      }
  </code></pre>
  
  <p>Controller </p>
  
  <pre><code>  public function search()
   {
   if(!isset($_GET['val']))
   {
   return call('pages','error');
   }
  
   $livre= Livre::findByCin($_GET['val']);
    //require_once('views/livres/index.php');
   }
  
  
   }
   ?&gt;
  </code></pre>
  
  <p>Model Function </p>
  
  <pre><code>      public static function findByCin($cin)
       {
  
        $db=Db::getInstance();
     $cin=intval($cin);
     $req=$db-&gt;prepare("SELECT * FROM document where ref like '%".$cin."%'");
       $req-&gt;execute();
       $list=[];
      foreach ($req-&gt;fetchAll() as $temp)
      {
       $Livre=new Livre();
         $Livre-&gt;setReference($temp['ref']);
        $Livre-&gt;setNom($temp['nom']);
        $Livre-&gt;setDateCreation($temp['date_creation']);
       $Livre-&gt;setPrix($temp['prix']);
       $Livre-&gt;setAuteur($temp['auteur']);
       $Livre-&gt;setnbPages($temp['nbrPages']);
       $list[]=$Livre;
       }
  
        return $list;
       }
  </code></pre>
  
  <p>HTML page </p>
  
  <pre><code>        &lt;div class="box"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;hr&gt;
              &lt;h2 class="intro-text text-center"&gt;
                  &lt;strong&gt;Liste des Livres&lt;/strong&gt;
  
              &lt;/h2&gt;
              &lt;hr&gt; &lt;br&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-sm-6"&gt;
                      &lt;a class="pull-left btn btn-default" href="?controller=chercheurs&amp;action=add"&gt;
                          Ajouter Livre&lt;/a&gt;
  
  
                          &lt;div class="col-sm-6"&gt;
  
                              &lt;form action="?controller=livres&amp;action=search" method="POST"&gt;
                                  &lt;div class="input-group"&gt;
                                      &lt;input  type="search" onkeyup="changement(this.value)" name="search" class="form-control" placeholder="Recherche par Réference" id="rech"&gt;
                                      &lt;span class="input-group-btn"&gt;
                                  &lt;button type="submit" class="btn btn-default"  &gt; Filtrer &lt;/button&gt;
                                      &lt;/span&gt;
                                  &lt;/div&gt;
                              &lt;/form&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;&lt;/div&gt;&lt;br&gt;
                      &lt;div class="table-responsive" id="tab"&gt;
                          &lt;table class="table table-stripped"&gt;&lt;thead&gt;
                              &lt;tr&gt;
                                  &lt;th&gt;Réference&lt;/th&gt;&lt;th&gt;Nom&lt;/th&gt;&lt;th&gt;DateCreation&lt;/th&gt;&lt;th&gt;Prix&lt;/th&gt;&lt;th&gt;Auteur&lt;/th&gt;&lt;th&gt;NbrPages&lt;/th&gt;
                              &lt;/tr&gt; &lt;/thead&gt;
                              &lt;tbody&gt;
                              &lt;?php foreach ($livre as $livr) {?&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;&lt;?php echo $livr-&gt;getReference(); ?&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;?php echo $livr-&gt;getNom(); ?&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;?php echo $livr-&gt;getDateCreation(); ?&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;?php echo $livr-&gt;getPrix(); ?&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;?php echo $livr-&gt;getAuteur(); ?&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;?php echo $livr-&gt;getnbPages(); ?&gt;&lt;/td&gt;
                                      &lt;td&gt;
                                      &lt;a class="btn btn-danger" href="?controller=livres&amp;action=delete&amp;id=&lt;?php
                                      echo $livr-&gt;getReference(); ?&gt;"&gt;
                                      Supprimer &lt;/a&gt;
                                      &lt;a class="btn btn-primary" href="?controller=livres&amp;action=edit&amp;id=&lt;?php
                                      echo $livr-&gt;getReference(); ?&gt;"&gt;
                                      Modifier &lt;/a
                                      &lt;/td&gt;
                                  &lt;/tr&gt; &lt;?php } ?&gt;
                              &lt;/tbody&gt; &lt;/table&gt;
                          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
  </code></pre>
  
  <p>thanks .</p>