gpt4 book ai didi

ajax - CakePHP 使用 ajax 加载模态内容

转载 作者:行者123 更新时间:2023-12-02 01:20:11 25 4
gpt4 key购买 nike

我想在我的导航栏上添加一个通知框。所以当我点击一个新的通知 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com