Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP使用ajax加载模式内容_Ajax_Cakephp_Modal Dialog - Fatal编程技术网

CakePHP使用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:

我想在导航栏上添加一个通知框。因此,当我点击一个新的通知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>
函数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控制台中没有错误,为什么
返回falseajax调用后?@Poonam当我删除它时,我得到了以下错误未捕获类型错误:document.getElementById(…).text不是函数(…),所以我不知道如何设置内容textUse
document.getElementById(“titre”).innerHTML=“New notification”