使用jQuery的$.ajax()函数,在success回调函数中使用html()方法将返回的HTML代码插入到页面中。
示例代码:
$.ajax({
url: "example.php",
type: "POST",
data: { name: "John", location: "Boston" },
dataType: "html",
success: function(response) {
$("div").html(response);
}
});
在这个例子中,Ajax请求使用POST方法将表单数据发送到example.php。服务器响应的内容被解释为HTML格式,并通过jQuery的html()方法插入到页面中的div元素中。
下一篇:Ajax请求数量不断增加。