form refresh, if statement not meeting condition

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?


   


  1. { alert('stage2');
  2. $.ajax(
  3. { type: 'POST',
  4. url: "emailposter.php",
  5. data: $('#emailForm1').serialize(),
  6. success: function(returned_data)
  7. { console.log(returned_data['msg']);
  8. if(msg == "saved")
  9. { $('.emailSuccess').fadeIn(200).show();
  10. $('.emailError').fadeOut(200).hide();
  11. $("#txt_email").val("");
  12. alert('stage3(worked)' + '  ' + msg);
  13. }
  14. alert('stage4(content of msg)-->: '+' ' + msg);
  15. },


  16. -----------------------------------------
  17. external php file
  18. if(!empty($_POST['txt_email']))
  19. {   echo 'saved';}
  20. else 
  21. {   echo 'Not Saved';}