繁体   English   中英

加载表单导致使用Ajax进行引导模态

[英]Load form results in bootstrap modal with ajax

问题:我想以引导模式显示表单页面的结果。

一切正常,但无法用表单页面中的数据替换模式主体内容。 我在哪里做错了转弯? 当我在警报中显示结果时,它的工作正常...

 // this is the id of the form $("#idform").submit(function(e) { e.preventDefault(); // avoid to execute the actual submit of the form. var form = $(this); var url = "form.html"; //form.attr('action'); $.ajax({ type: "POST", url: url, data: form.serialize(), // serializes the form's elements. success: function(data) { //alert(data); // show response from the php script. -> Working fine // Here is (i guess) the problem zone...: $("#modal-confirmation").modal('show').on("show", function(e) { $(this).find(".modal-body").load(data); }); } }); }); 

谢谢,谢谢您的帮助!

您可以使用:

$("#modal-confirmation .modal-body").html(data);
$("#modal-confirmation").modal('show');

您不需要使用load方法,因为您已经使用过ajax并获取数据,因此在需要时直接使用它...

 // this is the id of the form $("#idform").submit(function(e) { e.preventDefault(); // avoid to execute the actual submit of the form. var form = $(this); var url = "form.html"; //form.attr('action'); $.ajax({ type: "POST", url: url, data: form.serialize(), // serializes the form's elements. success: function(data) { //alert(data); // show response from the php script. -> Working fine // Here is (i guess) the problem zone...: $("#modal-confirmation").modal('show'); $("#modal-confirmation .modal-body").html(data); } }); }); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM