My first question so here it goes.
My goal is to have a simple form post and if everything checks out proceed.
$.post("anotherpage.php", $("#form").serialize(),function(data){
if(data == 'sent'){
alert("True: " + data);
} else{
alert("False: " + data);
}
$("#somediv").text(data);
});
here is ‘anotherpage.php’
<?php
echo 'sent';
?>
Here is my problem, ‘#somediv’ shows the word ‘sent’ but my function fails every time. Also when it does fail when it alerts it looks like this. “False: s…” It makes me think I have some problem up the stream that is effecting this but I don’t know what.
When trying to be explicit with your HTTP response, it’s easy to accidentally return extra whitespace, especially at the end of your PHP block (carriage returns after the closing angle-bracket being the usual suspects).
Some tips:
exit()on the last code line of your php block:e.g.
There are a few cool functions in PHP regarding output control. You can buffer the output, clear it, store it or flush it. See here for more information.