Fel*_*sen 9 jquery css-selectors jquery-selectors
我的页面设计迫使我用我通过ajax加载的html刷新整个页面.
$('html').replaceWith(data);
给我错误.有任何想法吗?
Rob*_*bin 23
我有同样的问题,但这没有帮助.如果您还需要更换<head>标签(所以,整个页面),您也可以这样做
document.write(newPage);
Run Code Online (Sandbox Code Playgroud)
cgp*_*cgp 18
使用身体:
$('body').replaceWith(data);
Run Code Online (Sandbox Code Playgroud)
我遇到了一些问题
$("body").replaceWith(newPage)
Run Code Online (Sandbox Code Playgroud)
给我一些奇怪的CSS问题,但这工作得很好:
$("body").html(newPage);
Run Code Online (Sandbox Code Playgroud)
这可能是您需要的解决方案,它会替换整个文档,包括其 head。加载新的 css、js 和其他资源不会有任何问题。我假设您通过调用 REST api 收到新的 html 内容:
$.ajax({
type: 'POST',
url: form.attr('action'),
data: form.serialize(), // serializes form elements
success: function(response) {
// re-writes the entire document
var newDoc = document.open("text/html", "replace");
newDoc.write(response);
newDoc.close();
}
});
Run Code Online (Sandbox Code Playgroud)