javascript - Send AJAX email by calling a function -


following js function have been trying send email contact form, used validation checks working fine when code goes send form process stops there , receives no responce $.ajax. strangely when used same code on click event $('#send_message').click(function(e){ worked fine not when removed click trigger listen , tried via calling function didnot work kindly let me know did wrong can fix issue of sending email calling function

 $.ajax({                     type:"post",                     url:"email.php",                     data: $("#contact").serialize(),                     success:function(result){                         //alert(response);                         if(result == 'sent')                         {                               $('#send_message').removeattr('disabled').attr('value', 'send info');                              //and show mail success div fadein                          }                         else                         {                              //show mail failed div                           }                      }                  }); 

you need return false. ongoing ajax postback canceled form submit.

so remove else.

jquery ajax supporting synchronous postbacks:

$.ajax({    type:"post",    url:"send_email.php",    data: $("#contact").serialize(),    async: false,    success:function(result){ 

edit: first solution should work important use return in form tag e.g. <form method="post" onsubmit="return somefunction();">


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -