使用 ajax 在 Bootstrap 模式中加载表单结果 [英] Load form results in Bootstrap modal with ajax

查看:25
本文介绍了使用 ajax 在 Bootstrap 模式中加载表单结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Bootstrap 模式中显示表单页面的结果.

I want to show the results of the form page in a Bootstrap modal.

一切正常,但不能用表单页面中的数据替换模态正文内容.我哪里转错了?当我在警报中显示结果时,它工作正常...

Everything is working, but not the replacement of the modal body content with the data from form page. Where I'm doing the wrong turn? When I show the results in an alert, its working fine...

// 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);     
               });                                           
           }
         });


});

推荐答案

不需要使用load方法,因为你已经使用了ajax并获取了数据,所以需要的时候直接使用...

You do not need to use load method because you already used ajax and get the data so use it directly when you need...

// 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);
                                                   
           }
         });


});

这篇关于使用 ajax 在 Bootstrap 模式中加载表单结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆