Bonsoir,
Je voudrais faire une boucle if selon ce que retourne html(data), ainsi comment obtenir une variable retournée par "form_treatment.php" ? J'aimerais effectuer une action selon la variable php retournée à ajax par html(data)
form.php :
form_treatment.php :
Modifié par Tchernobyl (30 Nov 2011 - 00:55)
Je voudrais faire une boucle if selon ce que retourne html(data), ainsi comment obtenir une variable retournée par "form_treatment.php" ? J'aimerais effectuer une action selon la variable php retournée à ajax par html(data)

$('#myForm').submit(function() {
var myForm = $(this);
$.ajax({
type: 'POST',
url: 'form_treatment.php',
data: myForm.serialize(),
success: function (data) {
$('#message').html(data);
// Make a if loop according to what returns html(data)
}
});
return false;
});
form.php :
<form method="post" action="form_treatment.php" >
<input type="text" name="user_name" value="Your name..." />
<button type="submit" >OK</button>
</form>
form_treatment.php :
<?php if ( empty($_POST['user_name']) ){
$a = false;
$b = "Name already used.";
} else {
$already_existing = verify_existence( $_POST['user_name'] );
// verification in the DB, return true or false
if( $already_existing ){
$a = false;
$b = "Name already used.";
} else {
$a = true;
$b = "Verification is OK";
}
}
Modifié par Tchernobyl (30 Nov 2011 - 00:55)