Hi guys,
This might spund a little bit funny, didn't even know how to put the title at first. It could be due to long hours of work or I'm just doing something wrong.
I have a file, say comment.php, which contains something similar to:
var params = $('form#myform').serialize();
$.get("/ajax/file.php?"+params, function(data){
if (data == 'error') {
$('#message').html('Error');
} else if (data == 'success') {
$('#message').html('Success');
}
});
I checked it with firebug and everything is ok, no JS errors, the file is being called and returns either 'error' either 'success', but still, in the body of the ajax call data doesn't match the server response. I then changed
if (data == 'error') {
$('#message').html('Error');
} else if (data == 'success') {
$('#message').html('Success');
}
with
if (trim(data) == 'error') {
$('#message').html('Error');
} else if (data == 'success') {
$('#message').html('Success');
}
where trim() is a function I wrote that removes any spaces before or after the string. I also tried wit the file being called echoing numbers and making the check with jQuery like:
if (data == 1) {
$('#message').html('Error');
} else if (data == 'success') {
$('#message').html('Success');
}
with no results. If I only alert(data) everything looks fine tough. Both files are on the same domain. My code is exactly as in the example just that I have more if/else conditions and one of them should allways match (it does if I look in firebug). I also tried using a switch statement with no result.
I've been using this method for some time now and never had any problems. Ideas?