我试图在 div 中显示我的 ajax 响应,但我不知道该怎么做。
我的代码如下:
<div class="divright">
Div Content
</div>
< script >
$(document).on("click", '.tribe-mini-calendar-day-link', function() {
var date = $(this).data('day');
$.ajax({
type: "POST",
url: TribeMiniCalendar.ajaxurl,
data: {
action: 'event_details',
date: date
},
success: function(response) {
console.log(response)
},
error: function(request, error) {
alert("FOUT:" + error);
}
})
})
</script>
如果您点击.tribe-mini-calendar-day-link
,控制台会显示以下内容:
`{status: true, html: "<p><strong>Pratice: </strong> 2017-09-23 till 2017-09-24</p>"}`
现在我的问题是,如何在 divright
中显示该代码?
最佳答案
你的成功函数应该是:
success: function (response) {
if(response !== undefined && response.html !== undefined) {
$(".divright").html(response.html);
}
},
关于javascript - 显示来自 Ajax 响应的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46297017/