Reputation:
The goal for my script is showing list of results from page1.php to page-listes.php
I incluse all method to my ajax call the sucess method was fired but page list not displayed
The ajax call code is :
$.ajax({
type: "POST",
url: "page-listes.php",
data: "name="+name+"&type="+type+"®ion="+region+"&aliment="+aliment+"&periode="+periode,
dataType: 'html'
}) .done(function() {
alert( "success" );
})
fail(function() {
alert( "error" );
})
.always(function() {
alert( "complete" );
});
And the php result file is :
<?php
try {
$bdd = new PDO('mysql:charset=utf8;host=localhost;dbname=reps-bd', 'tchiko', 'tchiko');
} catch (Exception $e) {
die('Erreur : ' . $e->getMessage());
}
if (isset($_POST['name'])) {
$name = $_POST['name'];
$type = $_POST['type'];
$region = $_POST['region'];
$aliment = $_POST['aliment'];
$periode = $_POST['periode'];
// recuperer la liste
$repListe = $bdd->query('SELECT re.libelle libeller, t.libelle libellet, r.nom nom, r.nb_personne nb, r.image image, r.date date
FROM course r
INNER JOIN region re ON r.id_region=re.id_pays
INNER JOIN type t ON t.id_type=t.id_type
WHERE r.nom LIKE "%'.$name.'%"')
or die(print_r($bdd->errorInfo()));
?>
// some html code
<?php
while ($cours= $repListe->fetch()){
$fch_image = 'images/temp/'.$cours['image'].'.jpg';
?>
<div class="offer_list clearfix">
<div class="offer_item clearfix">
<div class="offer_image"><a href="offers-details.html"><img src="<?php echo $fch_image;?>" alt=""></a></div>
<div class="offer_aside">
<h2><a href="offers-details.html"><?php echo strtoupper($cours['nom']);?></a></h2>
<div class="offer_descr">
<p>...............</p>
</div>
<div class="offer_data">
<div class="offer_price"><?php echo $cours['diff'];?></div>
<span class="offer_miliage"><?php echo $cours['libellet'];?></span>
<span class="offer_regist"><?php echo $cours['date'];?></span>
</div>
</div>
</div>
</div>
<?php
}
$repListe->closeCursor();
}
?>
// some html code
I think the php file was correct,but nothing happen when i call it
Upvotes: 0
Views: 66
Reputation: 119867
The problem is that your code doesn't have any mechanism to actually append the response to your page. For instance, if you had a <p>
with an id
of myParagraph
and want to append the response there, then your done
callback should look like this:
.done(function(response){
$('#myParagraph').html(response);
});
Upvotes: 1
Reputation: 1043
Developer tools in your browser is your friend :-) Right click -> Inspect element (Chrome/Firefox), switch to console tab and you will see what is wrong. You forgot dot before fail() method :-)
Upvotes: 0