我想在我的导航栏上添加一个通知框。所以当我点击一个新的通知 div 时,我想用我的通知文本显示我的模态,这里我使用了以下 ajax 函数,但它不能显示模态文本。
function viewPost(IDnotif){
var notifId = IDnotif;
var data = "id="+ notifId;
$.ajax({
type: "post", // Request method: post, get
url: base_url + "/icicpermis/notifications/getNotification/"+notifId,
data: data,
success: function(response) {
document.getElementById("myModal").style.display = "block";
document.getElementById("titre").text('New notification ');
},
error:function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
return false;
}
</script>
那是我的模态:
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content" id="content">
<span class="close">x</span>
<p id='titre'>Nouvelle notification </p>
</div>
</div>
最佳答案
在 javascript .text()
中将不起作用。您必须更改 #titre
html
因此,在 javascript 中使用 innerHTML
,
document.getElementById("titre").innerHTML = "New notification";
你也可以使用 jQuery
$('#titre').html('New notification');
在 ajax 调用后删除 return false;
因为它会隐藏错误。
关于ajax - CakePHP 使用 ajax 加载模态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40605808/