Alert on ajax succes and error

Résolu
Bonjour,
mon probleme est que l'alert ne fonctionne pas
voici le code:

<table align=center>
<form method="POST" action="" align="center" >
<tr colspan="2">
<td colspan="2" align=center><span style="color:#ff80aa;font-size:30px;" style="padding-bottom:50px;" > edition du profil:</span></td>
</tr>
<tr style="padding-bottom:50px;">
<td><label style="color:#ff80aa;font-size:25px;"> Nom: </label></td>
<td><input type="text" name="newnom" id="nom" placeholder="nom" value="<?php echo $user['nom']; ?>"></input></td>
</tr>
<tr style="padding-bottom:50px;">
<td><label style="color:#ff80aa;font-size:25px;" > Prenom: </label></td>
<td><input type="text" name="newprenom" id="prenom" placeholder="prenom" value="<?php echo $user['prenom']; ?>"></input></td>
</tr>
<tr style="padding-bottom:50px;">
<td><label style="color:#ff80aa;font-size:25px;" > adresse:</label></td>
<td><input type="text" name="newadresse" id="adresse" placeholder="adresse" value="<?php echo $user['adresse']; ?>"></input></td>
</tr>
<tr style="padding-bottom:50px;">
<td><label style="color:#ff80aa;font-size:25px;"> email:</label></td>
<td><input type="text" name="newmail" id="mail" placeholder="mail" value="<?php echo $user['email']; ?>"></input></td>
</tr>
<tr style="padding-bottom:50px;">
<td><label style="color:#ff80aa;font-size:25px;" id="tel"> tel:</label></td>
<td><input type="text" name="newtel" id="tel" placeholder="tel" value="<?php echo $user['tel']; ?>"></input></td>
</tr>
<tr style="padding-bottom:50px;" >
<td colspan="2" align=center><input type="submit" value="mettre à jour" onclick="mettre_a_jour();"></input></td>
</tr>

</form>
</table>

<script>
function mettre_a_jour(){
$.ajax({
type: "post",
url: "mise_a_jour.php",
data: {id_client: $_GET["id_client"] ,nom: $("#nom").val(), prenom: $("#prenom").val(), mail: $("#mail").val(), tel: $("#tel").val(), adresse: $("#adresse").val()},
success: function(){
return alert('changement enregistré');
},
error: function(){
return alert('inexistante');
}

});
}
</script>


et le code de mise_a_jour.php

<?php
$bdd= new PDO('mysql:host=localhost;dbname=magasin','root','');
nom = $_POST['nom'];
prenom = $_POST['prenom'];
tel = $_POST['tel'];
adresse = $_POST['adresse'];
email = $_POST['mail'];
id_client= $_POST["id_client"];
$query="UPDATE clients SET nom='{nom}' prenom='{prenom}' tel='{tel}' adresse='{adresse}' email='{email}' WHERE id_client='{id_client}'";
$stm1=$bdd->prepare($query);
$stm1->execute();
?>


merci pour toute aide :)

1 réponse

  1. Modérateur
    Bonjour,

    Pour commencer... change le "submit"
    <td colspan="2" align=center><input type="submit" value="mettre à jour" onclick="mettre_a_jour();"></input></td>
    

    par "button"
    <td colspan="2" align=center><input type="button" value="mettre à jour" onclick="mettre_a_jour();"></input></td>
    


    Ensuite... si ça ne fonctionne toujours pas... dis nous (voir même fais nous une capture écran) ce que contient la CONSOLE de ton navigateur (de préférence en utilisant le plugin FireBug pour Firefox.)

    1. j'ai trouver ma faute :) merci pour votre aide :)