jquery ajax Transfer de tableau d'une page a une autre
bonjour je cherche a faire transiter un tableau d'une page php(p2) a une autre(p1) mais je ne sais pas comment m'y prendre:pleure:.
page 1:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| <html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<title>Recherche de dossier DR</title>
</head>
<body>
<script>
function Reload(){
document.reload(true);
}
function trace(sTrace){
$("#trace").append(sTrace + "<br>");
}
$(document).ready(function() {
$( "#zonText" ).on("change paste keyup", function() {
var saisie = $( "#zonText" ).val();
if (saisie.length>=3) {
//trace("Longueur de saisie : " + saisie.length);
$.ajax({url:"recherche.php",
type:'get',
data:{
saisie:$('#zonText').val()
},
success: function(result){
trace("il y as "+saisie.length+" caracters");
}
})
}
});
} );
</script>
<div class="container">
<form action="./index.php">
<div class="form-group">
<label for="search">Numéro ou nom de dossier à chercher : </label>
<input class="form-control" type="text" id="zonText" autofocus maxlength="360">
</div>
<button type="submit" class="btn btn-default">Rechercher</button>
<!--button type="button" class="btn btn-default" onclick="Reload()">reset</button-->
<p id="trace">
</p>
</form>
<table class="table table-striped">
<thead>
<tr>
<th>Nom du dossier</th>
<th>Référence</th>
<th>Instance DR</th>
<th>Groupe</th>
<th>Date de modif</th>
<th>Type de dossier</th>
</tr>
</thead>
<tbody id='tabResult'>
<!-- remplir tableau avec $sResGlob -->
</tbody>
</table>
</div>
</body>
</html> |
page 2:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<?php
// Renvoie true si $haystack (une string) termine par $needle (string aussi)
function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
// Créer autant de fonctions que de méthodes de recherches
function search_preg_grep($sFile, $sNeedle){
$sResult = '';
$pattern = "/($sNeedle)/i";
$tab2colonnes = preg_replace('/([^;]*;[^;]*).*/i', "$1", file($sFile));
$matches = preg_grep($pattern, file($sFile));
$iPosLastSlash = strrpos($sFile, "/");
$iPosLastDot = strrpos($sFile, ".");
$sInstance = substr($sFile, $iPosLastSlash+1, $iPosLastDot-$iPosLastSlash-1);
if(count($matches) > 0)
{
foreach($matches as $sLine)
{
$sLineRes = preg_replace($pattern, "<span style=\"background-color:#f2ed54\">$1</span>", utf8_encode($sLine));
$tabLineRes = explode(";", $sLineRes);
if(count($tabLineRes) >= 10)
{
$sNom = $tabLineRes[0];
$sRef = $tabLineRes[1];
$sGroupe = $tabLineRes[4];
$sDate = $tabLineRes[8];
$sType = $tabLineRes[9];
$sResult.="<tr><td>$sNom</td><td>$sRef</td><td>$sInstance</td><td>$sGroupe</td><td>$sDate</td><td>$sType</td></tr>";
}
}
}
else{
}
return $sResult;
}
if(isset($_GET['search']))
{
// Lister les fichiers à analyser
$sPath = "./source/";
$sResGlob='';
$tabFiles = scandir($sPath);
$time_start= microtime(true);
$sSearchFor = $_GET['search'];
foreach($tabFiles as $sFile)
{
if(endsWith($sFile, "csv")){
$sResGlob.=search_preg_grep($sPath.$sFile, hFor);
}
}
$time_end = microtime(true);
$duree = $time_end - $time_start;
echo $sResGlob;
}
// Mesurer le temps d'éxécution de chaque méthode
?> |
j'aimerai mettre la variable $sResGlob de la page 2 dans <tbody id='tabResult'>.
je débute en ajax et j'ai pas des mas de connaissance en js (mais je me forme sur le net :arf::bug: