Your conditional statement never fires in your success function because it will always be false. (data == 'success')
will never work because your json encoding of that string returns the value, "success"
as opposed to success
. I don't know why you're json encoding it anyway, but you should do something else such as
$result = array(
'status' => 'success'
);
echo json_encode($result);
Then you can do
(data.status == 'success')
As far as redirecting after the result returns successful, after the following line:
$contactpage.find('.contact-form').hide();
You should do something like:
setTimeout(function(){
window.location = 'mydomain.tld/my-homepage.ext';
}, 5000);
And your element with the class of contact-thankyou
should have some type of text like, "We have received your submission. You will be redirected to the home page in 5 seconds.". Then after 5 seconds they will be redirected based on the previously defined setTimeout
function.
You also have an rn
at the end of your header declaration which i assume should be \r\n
, however you do not continue concatentation of the headers and therefore it is not required. Please review the RFC2822 on this.