Problème avec ajax

Fermé
mirakanto - 22 août 2011 à 10:27
 mirakanto - 22 août 2011 à 11:00
Bonjour,

Je veux faire une mise à jour d'une page avec ajax, mais j'ai un problème de code.Pouvez-vous m'aider s'il vous plait?Merci d'avance pour votre collaboration!
Voici mon code:

<?php
// print_r($_POST);
require_once 'config.php';

$query = "SELECT * FROM membres";

$filtre = array();

if(isset($_POST["nom"]) && $_POST["nom"] != "")
$filtre[] = sprintf("'nom' LIKE '%s' OR 'prenom' LIKE '%s'", "%".$_POST["nom"]."%", "%".$_POST["nom"]."%");
if(isset($_POST["civilite"]) && $_POST["civilite"] != "")
$filtre[] = sprintf("'civilite' = '%s'", $_POST["civilite"]);

if(count($filtre) != 0)
$query = $query." WHERE ".implode(" AND ", $filtre);

if(isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 0;

$par_page = 3;


$res = mysql_query($query);
$num_rows = mysql_num_rows($res);
echo "$num_rows Enregistrements\n";
$query = sprintf("%s LIMIT %d, %d", $query, $page*$par_page, $par_page);

//echo $query;

$res = mysql_query($query) OR die (mysql_error());
?>

<script language="javascript">
function confirme(){
var confirmation = confirm("Voulez vous vraiment supprimer cette personne?");
if(confirmation){
return true;
}
return false;
}
function affichage(param){
var new_action = param.href;//le tery ambany
document.getElementById("filtre").action = new_action; //soloina ny action anle forme
document.getElementById("filtre").submit();
return false;
}

</script>
<script type="text/javascript" src="scripts/jquery-1.4.2.min.js">

</script>
<form method="post" action="liste.php" id="filtre">
<table cellpadding="0" cellspacing="0">
<tr><td><a href="form.php">Formulaire</td></tr>
<tr align="left">
<td>Rechercher par nom: </td>
<td><input type="text" name="nom" id="filtre" value="<?php if(isset($_POST["nom"])) echo $_POST["nom"]; ?>"></td>
<td><input type="submit" name="cherche" value="Chercher"<?php if(isset($_POST["cherche"])) echo $filtre; ?>></td>
</tr>
<td>Rechercher tous les: </td>
<td><select name="civilite">
<option value="" <?php if(isset($_POST["civilite"]) && $_POST["civilite"] == ""){ echo 'selected="selected"'; } ?>>Tous</option>
<option value="Mr" <?php if(isset($_POST["civilite"]) && $_POST["civilite"] == "Mr"){ echo 'selected="selected"'; } ?>>Mr</option>
<option value="Mme" <?php if(isset($_POST["civilite"]) && $_POST["civilite"] == "Mme"){ echo 'selected="selected"'; } ?>>Mme</option>
<option value="Mlle" <?php if(isset($_POST["civilite"]) && $_POST["civilite"] == "Mlle"){ echo 'selected="selected"';} ?>>Mlle</option>
</select></td>
</tr>
</table>
</form>
<table width="100%" border="1">
<?php if(isset($_GET["msg"])) :?>
<tr>
<td colspan="10">
<?php echo $_GET["msg"]; ?>
</td>
</tr>
<?php endif ?>
<tr>
<th width="2">Civilité</th>
<th width="50" align="center">Nom</th>
<th width="20" align="center">Prénom</th>
<th width="20" align="center">Date de naissance</th>
<th width="20" align="center">Profession</th>
<th width="20" align="center">Ville</th>
<th width="3" align="center">Code Postal</th>
<th width="20" align="center">Téléphone</th>
<th width="5" align="center">E-mail</th>
<th width="5" align="center">Action</th>
</tr>
<?php
while($data = mysql_fetch_array($res)){
?>

<tr valign="top">
<td align="center" class="td1"><?php echo $data["civilite"];?></td>
<td align="center" class="td2"><strong><?php echo $data["nom"]; ?></strong></td>
<td align="center" class="td3"><i><?php echo $data["prenom"]; ?></i></td>
<td align="center" class="td4"><?php echo $data["date_nais"]; ?></td>
<td align="center" class="td5"><?php echo $data["profession"]; ?></a></td>
<td align="center" class="td6"><?php echo $data["ville"]; ?></td>
<td align="center" class="td7"><?php echo $data["cp"]; ?></td>
<td align="center" class="td8"><?php echo $data["telephone"]; ?></td>
<td align="center" class="td9"><?php echo $data["email"]; ?></td>
<td align="center" class="td8"><a href="maj.php?id_membre=<?php echo $data["id_membre"]; ?>"><a href="javascript:void(0);" id="filtre">Editer</a></a>   
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$('#a').click(function(){
$.ajax({
'async': 'true',
'type': 'POST',
'url': 'maj.php',
success: function(response){
var idmem = document.getElementById("filtre");
}
});
});
</script>
<script type="text/javascript">$("#id_membre");</script>
<a href="supprime.php?id_membre=<?php echo $data["id_membre"]; ?>"onclick="return confirme();">Supprimer</a></td>
</td>
</tr>
<?php } ?>
</table>

<table>
<tr align="center">
<td>
<?php
$nb_page = ceil($num_rows/$par_page);
for($i=0; $i<$nb_page; $i++){
if($page == $i){
echo "$i";
}else
//echo '<a href="liste.php?page='."".$i.'"> '.$i.' </a>';
echo '<a href="liste.php?page='."".$i.'" onclick="return affichage(this);"> '.$i.' </a>';
}
?>
</td>
</tr>
</table>

Cordialement!
mirakanto

1 réponse

jill_ Messages postés 1294 Date d'inscription lundi 18 juillet 2011 Statut Membre Dernière intervention 21 janvier 2015 560
22 août 2011 à 10:29
Bonjour

Decris nous un peu ton probleme
0
mon problème c'est que quand l'utilisateur clique sur editer, on affiche la page maj.php et on peut faire la modification!et je veux le faire avec ajax.La page maj.php doit afficher sur la même page!Merci d'avance!
0