javascript - AJAX 表单提交不重新加载内容
问题描述
我在这里看到了很多问题和答案,但似乎没有一个能解决我的问题。我有一个表单,它从 ajax 加载调用加载到一个名为动态内容的 div 类中。基本上,如果按下表单提交按钮,我希望它在 ajax 中重新加载此表单,以便它执行 php 表单验证。我的问题是,当提交发生时,我调用 ajax 加载以通过 javascript 重新加载,但它没有触发,而是返回到当前索引页面。我的JS如下:
$(document).ready(function () {
//Handle AJAX request from sidebar buttons
var trigger = $('.submit-btn'),
container = $('.dynamic-content');
$(".add-customer-form-btn").submit(function() {
// do something...
alert('test');
container.load('customers/customersaddform.php',$("form").serializeArray());
return false;
});
});
我在customersaddform.php 中的html 表单被加载到位于主索引文件的动态内容div 中。
<?php
//FORM VALIDATION CHECKS
?>
<form action="" method="post">
<div class="form-field add-customer-form">
<div class="container-fluid">
<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<h4>Account Information</h4>
<div class="row">
<div class="col-md-6 label-container">
<div class="input-group input-group-icon">
<input type="text" placeholder="First Name" name="first-name" required/>
<div class="input-icon"><i class="fa fa-user"></i></div>
<div class="input-error-msg"><?php echo $first_name_err;?></div>
</div>
</div>
<div class="row">
<div class=col-md-12 label-container">
<input type="submit" class="add-customer-form-btn submit-btn" value="Submit">
</div>
</div>
</div>
</div>
</form>
解决方案
推荐阅读
- python - 将矩阵列转换为对角矩阵并在没有 for 循环的情况下将它们包装起来
- javascript - “TypeError:kinds.map 不是函数。” 反应.js
- c++ - 片段着色器中的 GLSL 翻译未按预期工作
- html - 使用计数器垂直对齐嵌套列表中列表项中的块级元素?
- glsl - 在 GLSL 上绕过矩阵乘法
- javascript - 如何在 whatsapp-web.js 中发送 whatsapp 消息
- javascript - 如果路径是可变的,如何使用可选链接?
- gitlab - 错误:文件写入错误:错误的文件描述符致命:使用 git add 时无法写入 sha1 文件
- javascript - 为什么我的反应路由器 v6 代码不起作用,导航未加载组件
- c# - 使用 Microsoft Azure 认知服务检测模型:表单识别器