要获取Ajax返回页面的HTML代码而不是响应,可以使用jQuery的$.ajax()方法并设置dataType参数为"html"。以下是一个示例代码:
$.ajax({
url: "your-url",
dataType: "html",
success: function(response) {
// response变量包含返回的HTML代码
console.log(response);
},
error: function(xhr, status, error) {
console.error(error);
}
});
在上面的示例中,将your-url替换为你要请求的页面的URL。当请求成功时,success回调函数将被触发,其中response参数包含返回的HTML代码。如果请求失败,error回调函数将被触发,可以在其中处理错误情况。
请确保在使用该示例代码之前,先引入jQuery库。
下一篇:Ajax返回值