My form is returning data from PHP via jQuery. How can I create conditional statements based on the response in jQuery.
This is the jQuery:
$.ajax({
type: "POST",
url: "createAlbum.php",
data: postData,
success: function(data){
$('#message').fadeIn();
$('#message').html(data);
}
});
This is what it is returning from PHP:
if($error) {
echo $error;
}
else {
echo $success;
}
So if the response is success, the message should hide after a few seconds, but if it is an error, it should wait till the user corrects it. Something like this:
success: function(data){
$('#message').fadeIn();
$('#message').html(data);
if (data.response == 'success') {
alert('Success');
setTimeout(function() {
$('#message').fadeOut();
}, 5000 );
} else if (data.response == 'error') {
alert('Error');
}
}