【问题标题】:CakePHP use ajax to load modal contentCakePHP 使用 ajax 加载模态内容
【发布时间】: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


【解决方案1】:

在 javascript 中 .text() 将不起作用。你必须改变#titrehtml

所以,在 javascript 中使用innerHTML

document.getElementById("titre").innerHTML = "New notification";

你也可以使用 jQuery

$('#titre').html('New notification');

在ajax调用后删除return false;,因为它会隐藏错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-07
    • 2012-08-11
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 2011-04-19
    相关资源
    最近更新 更多