在我的ajax代碼中,我得到了一個html響應。我怎樣才能將整個頁面替換爲這個html響應?我只找到window.location.href
,它只能重新訪問url響應。jQuery - 在整個頁面中加載html響應
我的代碼:
$('#btn').click(function(){
$.ajax({
url: '/someurl',
data: {'key': value},
type: 'POST',
success: function(html_data) {
# how to load this html_data into the whole page?
},
error: ...
});
});
嗨,我只是在問題上添加我的代碼。我寫了$('html')。replateWith(html_data),但得到錯誤:「jquery.js:5894 Uncaught HierarchyRequestError:未能在'Node'上執行'replaceChild':'#document-fragment'類型的節點可能不是插入'#document'類型的節點中。「 – Joe
FIne,我只是使用$('html')。html(html_data)來解決這個問題。謝謝! – Joe
很高興幫助:) – shramee