我有一个模式,可以进行产品注册。我想在模态中提交一个表格而不离开模态。
<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<form method="post">
<button type="submit">Submit</button>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
答案 0 :(得分:16)
在我的情况下,我只将提交按钮设为页脚主体 并删除数据关闭 即:
<div class="modal-content">
<form id="role-form" method="get">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">تعديل صلاحيات المدير - {{$user->username}}</h4>
</div>
<div class="modal-body">
<div class="form-group col-md-12">
<select id="role" name="role" class="form-control">
<option selected disabled>الصلاحية</option>
<option value='1'>مدير</option>
<option value='2'>مشرف</option>
</select>
</div>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" >حفظ</button>
<button type="button" class="btn btn-default" data-dismiss="modal">إلغاء</button>
</div>
</form>
</div>
答案 1 :(得分:12)
首先,在<form>
代码上设置ID:
<form id="myForm" method="post">
...
</form>
如果你使用jQuery(强烈推荐),你可以这样做:
$(function(){
$('#myForm').on('submit', function(e){
e.preventDefault();
$.post('http://www.somewhere.com/path/to/post',
$('#myForm').serialize(),
function(data, status, xhr){
// do something here with response;
});
});
});