首页 > 解决方案 > 无法在不使用 php 和 ajax 调用重新加载页面的情况下提交表单

问题描述

我在一个页面上有很多表格。我想提交每个表单而不重新加载页面。我尝试了很多方法,但都做不到。我有一个类似的表格。我也尝试过使用ajax,但做不到。请帮我。现在,我也无法插入数据库。

   <form id="a" onsubmit="return func();">
       <input type="text" name="fname">
       <input type="text" name="lname">
       <input type="text" name="email">
       <input type="submit">
      </form>

jQuery

     function func(){   
    $.ajax({
          url:'registration_detail.php?id=' +reg_id,// in this you got serialize form data via post request
        type    : 'POST',
        data    : $('#a').serialize(),
        success: function(response){
            console.log(response);            
        }
    });
     return false;
}

标签: phpjquery

解决方案


不要使用“ action ”属性,即使是“ #

如果使用 AJAX,请使用“ Return False

    $.ajax({
        url     : "example.php",
        type    : 'POST',
        data    : $(this).serialize();
        success: function(result){
        }
    });
    return false;

推荐阅读