Django Bootstrap Modal Ajax-第一次完美运行,第二次-没有运气

问题描述 投票:0回答:1

我正在使用带有Bootstrap的Django 2.2。

这是用于[]的[C0

  1. 打开模式窗口,
  2. 用户更新数据,
  3. 用户保存它
  4. 打开窗口的基础表已更新,而模式窗口已关闭

到这里一切都工作正常,但是,当您单击同一按钮打开窗口时,就会出现问题。在这里,当您单击按钮时,什么也没有发生!

这是javascript文件。

approach

html_planner_client_list的输出如下:

            $("#modal-risk-profile").on("submit", ".form-risk-profile", function () {
            var form = $(this);         

            $.ajax({
                url:form.attr("action"),
                data:form.serialize(),
                type:form.attr("method"),
                dataType:'json',
                success: function(data) {
                    console.log(data.form_is_valid);
                    if(data.form_is_valid) {
                        console.log(data.html_planner_client_list);
                        $("#id_client_table tbody").html(data.html_planner_client_list); // if you remove this line, modal window appears without any issues
                        $("#modal-risk-profile").modal("hide");
                        console.log("I have returned with success");
                    }
                    else {
                        console.log("I am in else");
                        $("#modal-risk-profile .modal-content").html(html_form);
                    }                       
                }
            });

            return false;
        }); 

在检查器日志中没有错误,在Django中也没有错误。

可能会出什么问题?

javascript django ajax modal-dialog
1个回答
0
投票

我使用此<tr> <td> Rajesh </td> <td> 01-04-2000 </td> <td> Bangalore </td> <td> [email protected] </td> <td> Salaried </td> <td class="text-center"> <button class="button-risk-profile btn btn-danger btn-sm py-0" style="font-size:0.9em" data-url="/client/riskprofileplanner/19/"> Take Questionnaire </button> </td> <td> Subramanian</td> <td class="text-left"> <a href="/client/client_select/19/" class="btn btn-primary btn-sm py-0" style="font-size: 0.9em;">Select </a> <a href="/client/client_edit/19/" class="btn btn-primary btn-sm py-0" style="font-size: 0.9em;">Edit </a> <a href="/client/client_report/19/" class="btn btn-primary btn-sm py-0" style="font-size: 0.9em;">Report </a> <button class="button-choose-planner btn btn-primary btn-sm py-0" style="font-size: 0.9em;" data-url="/client/select_planner/19/"> Planner </button> </td> 解决了这个问题:

link

我改为:

            $('.button-risk-profile').click(function(){

            var btn = $(this);
            console.log("I am in client Risk Profile")

            $.ajax({
              url: btn.attr("data-url"),
              type: 'get',
              dataType: 'json',
              beforeSend: function () {
                $("#modal-risk-profile").modal("show");
              },
              success: function (data) {
                $("#modal-risk-profile .modal-content").html(data.html_form);
              }
            });             

        });
© www.soinside.com 2019 - 2024. All rights reserved.