更新时间:2023-12-05 10:44:40
您无法看到AJAX加载,因为页面是只要你点击锚点重装内容。通过使用 preventDefault()
禁用锚事件,这应该修复它。
You are not able to see content loaded by AJAX because the page is reloading as soon as you click the anchor. Disable the anchor event by using preventDefault()
and this should fix it.
<script type="text/javascript">
var page = 1;
$(document).on('click','.BlogButton',function(e){
// stop page from reloading
e.preventDefault();
$("#posts").load("miniBlog.php", function(response, status, xhr) {
if (status == "error") {
var msg = "Error!: ";
alert(msg);
}
});
page++;
});
</script>