javascript - action="javascript:void(0) 时提交表单
问题描述
我有 html 步骤表单 我需要在表单通过验证并填写所有字段后提交表单。我有一个动作控制器 register.php 但在我的 html 表单中我也有 action="javascript:void(0);" 那么如何提交我的表单操作。
<div class="form-bottom">
<div class="row">
<div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
<input type="text" class="form-control" placeholder="addres 1" id="add1" name="" value="" |>
</div>
<div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
<input type="text" class="form-control" placeholder="address 2" id="add2" name="" value="">
</div>
<div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
<input type="text" class="form-control" placeholder="city" id="city" name="" value="" |>
</div>
</div>
<div class="row">
<div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
<input type="text" class="form-control" placeholder="Home Phone" id="contact_number" name="" value="">
</div>
</div>
<div class="form-group col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12">
<input type="checkbox" name="vehicle" value="Car" checked> I Agree<br>
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="submit" class="btn">Submit</button>
</div>
解决方案
您可以使用 ajax 查询将数据发送到 php 脚本。
该代码插入 onsubmit 函数:
var formData = $(form_selector).serialize(); //Getting data from form
$.ajax({
type: "POST",
url: URL to php script,
data: formData,
success: function(data) {
//Action if data successfully sended, it's not nessesary
}
});
您可以在https://api.jquery.com/Jquery.ajax上了解有关 jQuery ajax 的更多信息
推荐阅读
- uber-api - Uber API 发生了什么变化?服务器是否已关闭?近期有重新开张的计划吗?
- c# - TCP Socket ReceiveAsync 有时需要很长时间
- reactjs - 反应:按钮不起作用(onClick) - 应该传递给 index.js 但没有任何反应
- android - 重新创建没有按钮的条件片段
- c# - 如何检测一个单词是否在文本框中重复
- windows - Get-ChildItem 在没有“Where”的路径中带有野生字符
- oracle - 从加入oracle的表中获取状态
- excel - How to get the border sizes of a userform?
- swift - Retrying old request after refreshing access token
- scala - run scala test from Intellij