【发布时间】:2016-11-15 17:57:29
【问题描述】:
我想在我的导航栏上添加一个通知框。所以当我点击一个新的通知 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>
【问题讨论】:
-
控制台有错误吗?
-
@Poonam 控制台没有错误
-
为什么在 ajax 调用之后这个
return false;? -
@Poonam 当我删除它时,我收到以下错误 Uncaught TypeError: document.getElementById(...).text is not a function(...) 所以我不知道如何设置内容文本
-
使用
document.getElementById("titre").innerHTML = "New notification";
标签: ajax cakephp modal-dialog