Ajax提交请求后台返回一个完整的html页面,怎么在新的窗口打开?

要在新的窗口打开后台返回的完整HTML页面,可以使用JavaScript中的window.open方法。以下是一个使用Ajax请求返回的HTML页面在新窗口中打开的示例代码:

“`javascript

// 创建一个XMLHttpRequest对象

var xhr = new XMLHttpRequest();

// 发起Ajax请求

xhr.open(‘GET’, ‘/your-url’, true);

xhr.onreadystatechange = function() {

if (xhr.readyState === 4 && xhr.status === 200) {

// 后台返回的HTML页面内容

var htmlContent = xhr.responseText;

// 打开一个新窗口并将HTML页面内容加载进去

var newWindow = window.open();

newWindow.document.write(htmlContent);

newWindow.document.close();

}

};

xhr.send();

“`

注意,在上面的代码中,需要将`/your-url`替换为实际的后台URL地址。另外,需要确保后台返回的是完整的HTML页面,而不仅仅是页面的片段或部分内容。通过将HTML内容写入新窗口的document对象,然后关闭document,就可以在新的窗口中显示完整的HTML页面。

# 回答此问题

后才能回答