如何获取表单发布的结果以显示在 Bootstrap 3 的模式窗口中?
我有一个项目列表,每个项目都有一个“编辑”按钮。单击编辑按钮时,我需要发布到表单并触发带有响应的模式弹出窗口。我正在尝试使用 jQuery 来做到这一点.ajax()
函数,我不确定这是否是最好的方法:
$(".editForm").submit(function() {
$.ajax({
type : "POST",
cache : false,
url : "./edit_form.php",
data : $(this).serializeArray(),
success: function() {
## How do I get the response to show up in a Bootstrap 3 modal? ##
}
});
return false;
});
但是,当需要解析表单发布的结果时,我陷入了困境。如何让它出现在 Bootstrap 3 的模式弹出窗口中? Bootstrap 文档讨论了从锚点链接触发模式<a data-toggle="modal" href="remote.html" data-target="#modal">Click me</a>
,但是如何通过表单帖子触发它?
也许我在倒退思考,或者把它过于复杂化了。也许我应该先打开模式,然后提交.ajax()
形成帖子,然后更新<div>
与结果。我习惯使用 Fancybox,并且正在将所有模态切换到 Bootstrap。
Thanks!
创建模态元素
<div id="modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
并在 dom 就绪时初始化它
//create the modal
$('#modal').modal({
show: false
});
然后在您需要时将其与消息一起显示
$('#modal .modal-body').html('Test: '+new Date());
$('#modal').modal('show');
Demo: Fiddle http://jsfiddle.net/arunpjohny/5UUDF/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)