我想用javascript ajax從另一個頁面加載div內容(該頁面在另一個運行在tomcat中的項目中)。從另一頁加載Div內容
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8080/prob-services/clogin#login_page');
xhr.onload = function() {
alert(xhr.status);
console.log(xhr);
if (xhr.status === 200) {
var modal = document.getElementById("modal_dialog");
modal.innerHTML = xhr.responseText;
}
};
xhr.send();
問題是,當我登錄xhr
我看到responseURL
是直到#
,所以阿賈克斯需要的只是http://localhost:8080/prob-services/clogin
代替http://localhost:8080/prob-services/clogin#login_page
。這就是它加載整個頁面的原因。 有沒有什麼辦法可以讓沒有JQuery的div內容?
不,你必須加載整個頁面,然後篩選在響應處理通緝格。或者你可以設置服務器根據url中的參數發送這個小部分,但是這需要更長的時間才能編碼,並且超出了問題的範圍。 –
散列標記'#'是僅由客戶端介入的片段標識符。您需要過濾客戶端上的內容或切換到請求變量,如「http:// localhost:8080/prob-services/clogin?page = login_page」 –
如何過濾它? –