AJAX: Submitting a form without refreshing the page

前端 未结 8 2000
感动是毒
感动是毒 2020-11-30 11:43

I have a form similar to the following:

相关标签:
8条回答
  • 2020-11-30 12:29

    You haven't provided your full code, but it sounds like the problem is because you are performing the $.post() on submit of the form, but not stopping the default behaviour. Try this:

    $('#myForm').submit(function(e) {
        e.preventDefault();
        $.post('mail.php', $('#myForm').serialize());
    });
    
    0 讨论(0)
  • 2020-11-30 12:29

    try this..

    <form method="post" action="mail.php" id="myForm" onsubmit="return false;">
    

    OR

    add

    e.preventDefault(); in your click function

     $(#yourselector).click(function(e){
          $.post('mail.php', $(this).serialize());
          e.preventDefault();
     })
    
    0 讨论(0)
提交回复
热议问题