I have this Ajax call which submits a form and shows different things depending on the response from the server:
$('#applyForm').submit(function(){
var dataString = $(this).serialize();
$.ajax({
type: "POST",
url: "php/common/apply/apply.php",
data: dataString,
success: function(data) {
if(data=='1'){
$('#formDiv').fadeOut();
$('#ok').fadeIn();
}
else if(data=='0') {
$('#warning').fadeIn();
}
else if(data=='-1') {
$('#error').fadeIn();
}
else {
alert(data);
}
}
});
return false
});
Is this the correct way of doing it?!
Thanks!
If the alert is showing
1then the response doesn’t equal any of the condition checks. I think you have some whitespace at the beginning or end of the response causing thedata == '1'check to evaluate tofalse.Try trimming your response on the PHP side, or do it on the Javascript side like: