php - 无法在不使用 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;
}
解决方案
不要使用“ action ”属性,即使是“ # ”
如果使用 AJAX,请使用“ Return False ”
$.ajax({
url : "example.php",
type : 'POST',
data : $(this).serialize();
success: function(result){
}
});
return false;
推荐阅读
- azure-devops-extensions - 我创建了一个自动创建子任务的规则,但它不起作用
- php - 将图像上传到 tmp 文件夹时出现问题,调整大小然后上传到 S3 存储桶
- python - Project Euler 7. 10001st prime
- javascript - 为图像模式选择多个元素
- terminal - PhpStorm 中集成终端的问题
- python - parse_and_bind() 用于其他键
- php - PHP CURL 数组过滤器 - 日期变量
- css - Chrome 74 iframe 样式在页面交互(悬停、焦点、开发检查、窗口调整大小)之前不会生效
- c++ - 围绕 std::string 和 std::string_view 构建一个包装类
- javascript - 我已经为元素的宽度设置了动画,但是动画开始时元素的边框消失了