Ajax form respond "OK" return

Ajax form respond "OK" return

Hi all,

I am trying to send a form to an email address and if the email sends properly my php return only 'OK'. This works fine but instead of my .ajaxComplete function recognizing that 'OK' is being returned it is simply echo-ing 'OK' directly to my page. I want to instead hide the form and fill a div with a custom message.

Can someone please shed some light on why this is happening and what I need to do. Thank you for any insights you may/can provide.

 I'm using jQuery 1.7.2. And, here is my code:

  1. jQuery(document).ready(function() {

  2. jQuery("#form_431558").submit(function() {
  3. var str = jQuery(this).serialize();
  4. jQuery.ajax({
  5. type : "POST",
  6. url : "php/contact.php",
  7. data : str,
  8. dataType : "html",
  9. success : function(msg) {
  10. jQuery("#note").ajaxComplete(function(event, request, settings) {
  11. if(msg == "OK") {
  12. result = '<h2>Thank you!<\/h2><p>Your message has been sent.<\/p><img id="checkmark" src="img/check.png" \/>';
  13. jQuery("#form_431558").hide();
  14. } else {
  15. result = msg;
  16. }
  17. jQuery(this).html(result);
  18. });
  19. }
  20. });
  21. return false;
  22. });
  23. });