要实现通过Ajax调用来输出div,可以按照以下步骤进行:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
document.getElementById("outputDiv").innerHTML = xhr.responseText;
}
};
xhr.open("GET", "your_ajax_url_here", true);
xhr.send();
或者使用jQuery的示例代码:
$.ajax({
url: "your_ajax_url_here",
method: "GET",
success: function(response) {
$("#outputDiv").html(response);
}
});
This is the content to be output";
echo $output;
?>
在以上示例中,当Ajax调用发生时,服务器将收到请求并返回需要输出的内容。然后,JavaScript通过获取返回的内容,并将其插入到指定的div中,完成了通过Ajax调用输出div的操作。