我正在使用带有Bootstrap的Django 2.2。
这是用于[]的[C0
到这里一切都工作正常,但是,当您单击同一按钮打开窗口时,就会出现问题。在这里,当您单击按钮时,什么也没有发生!
这是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中也没有错误。
可能会出什么问题?
我使用此<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);
}
});
});