我有一个关于点击它的链接正在发送ajax
请求并成功获得响应,这是html文件,我将附加到div
,但我需要将div
显示为modal popup
我试过以下内容。
html
<{1>}文件中的
<a th:if="${ratingSummary}" href="#" class="small dark account review_ratings_login">Login to write a review</a>
<div id="login_for_review" data-toggle="modal" data-target="#reviewLoginModal"></div>
js
档案
$(document).on('click', '.review_ratings_login', function () {
var $data = $('#review_product_id span').text();
var url = '/mycompany/login/'+$data;
$.ajax({
type: 'GET',
url: url,
success: function (output) {
$('#login_for_review').html(output).modal('show');// I tried to show this response as modal popup
},
error: function(output){
alert("fail");
}
});
});
但是我没有将此output
作为<div class="centerForm modal fade" role="dialog" style="margin-left: 35%;" id="reviewLoginModal">
<div class="modal-dialog modal-sm" >
<div class="modal-content">
// here I have login form
</div>
</div>
,而是我得到html output
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:4)
在Bootsrap模式弹出窗口中,您可以使用简单的方式来显示不需要预定义模态div容器的模态。见modal
对于E.g
$.ajax({
url: "url",
type: 'POST',
dataType: "html",
data:{id:params},
success: function(data, status, xhr) {
if(data==""){
window.location.href="/";
}
else{
BootstrapDialog.show({
title: "Modal Tital",
message: function(dialogRef){
$mydata = $($.parseHTML(data));
return $mydata;
},
onshow: function(dialog){
// and css change if need, eg.
dialog.$modalHeader.css("float","none");
},
onshown:function(dialog)
{
// event after shown
},
onhide:function(dailog)
{
// event on hide
}
});
}
},
statusCode: {
401: function () {
alert("Your session has been expired");
}
}
});
答案 1 :(得分:0)
我通过创建模态并删除data-toggle
和data-target
并仅添加对modal div
代码对于模态div
<div id="login_for_review" class="modal hide" role="dialog">
</div>
代码用于超链接
<a th:if="${ratingSummary}" href="#" class="small dark account review_ratings_login">Login to write a review</a>
ajax调用代码
$(document).on('click', '.review_ratings_login', function () {
var $data = $('#review_product_id span').text();
var url = '/mycompany/login/'+$data;
$.ajax({
type: 'GET',
url: url,
success: function (output) {
$('#login_for_review').html(output).modal('show');//now its working
},
error: function(output){
alert("fail");
}
});
});