form refresh, if statement not meeting condition
Hello,
this is regarding form submitting without refreshing the page.
I think i isolated the problem (i think) but not sure how to go about fix or handle the problem.
I highlighted the problem area in red. the msg and "saved" conditions are not being met.
after some troubleshooting and searching i learned the value returned is a object and therefore it will never meet the if statement condition.
the value returned in msg is "saved" confirmed by the alert stage4 but its not equaling msg == 'saved'. its bypassing the if statement.
added debug screenshot.
how do i go about fixing this problem?
- { alert('stage2');
- $.ajax(
- { type: 'POST',
- url: "emailposter.php",
- data: $('#emailForm1').serialize(),
- success: function(returned_data)
- { console.log(returned_data['msg']);
- if(msg == "saved")
- { $('.emailSuccess').fadeIn(200).show();
- $('.emailError').fadeOut(200).hide();
- $("#txt_email").val("");
- alert('stage3(worked)' + ' ' + msg);
- }
- alert('stage4(content of msg)-->: '+' ' + msg);
- },
-
-
- -----------------------------------------
- external php file
- if(!empty($_POST['txt_email']))
- { echo 'saved';}
- else
- { echo 'Not Saved';}
-
-
-
-
-