CakePHP使用ajax加载模式内容
我想在导航栏上添加一个通知框。因此,当我点击一个新的通知div时,我想用我的通知文本显示我的模态,在这里我使用了下面的ajax函数,但它不能显示模态文本CakePHP使用ajax加载模式内容,ajax,cakephp,modal-dialog,Ajax,Cakephp,Modal Dialog,我想在导航栏上添加一个通知框。因此,当我点击一个新的通知div时,我想用我的通知文本显示我的模态,在这里我使用了下面的ajax函数,但它不能显示模态文本 function viewPost(IDnotif){ var notifId = IDnotif; var data = "id="+ notifId; $.ajax({ type: "post", // Request method: post, get url:
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>
函数viewPost(IDnotif){
var notifId=IDnotif;
var data=“id=”+通知;
$.ajax({
类型:“post”,//请求方法:post,get
url:base_url+“/icicpermis/notifications/getNotification/”+notifId,
数据:数据,
成功:功能(响应){
document.getElementById(“myModal”).style.display=“block”;
document.getElementById(“titre”).text(“新通知”);
},
错误:函数(XMLHttpRequest、textStatus、errorshown){
警报(文本状态);
}
});
返回false;
}
这就是我的模态:
<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>
x
新通知
javascript中的。text()
将不起作用。您必须更改#titre
因此,在javascript中使用innerHTML
document.getElementById("titre").innerHTML = "New notification";
您也可以使用jQuery
$('#titre').html('New notification');
删除返回false代码>在ajax调用之后,因为它将隐藏错误。控制台中有错误吗?@Poonam控制台中没有错误,为什么返回false代码>ajax调用后?@Poonam当我删除它时,我得到了以下错误未捕获类型错误:document.getElementById(…).text不是函数(…),所以我不知道如何设置内容textUsedocument.getElementById(“titre”).innerHTML=“New notification”代码>