亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用JS獲取遠程頁面的HTML內容

用JS獲取遠程頁面的HTML內容

浮云間 2023-10-10 16:42:03
如何從遠程網站(遠程 PHP 腳本的輸出)提取 HTML 內容,以通過 .html 文件顯示,而無需運行 Web 服務器并使用純 JS(如果 vanillaJS 太復雜,則使用 Ajax)。無法將https://quarantine.country/coronavirus/cases/usa/輸出包含到 covid 應用程序(無 apache,僅 html)且 jQuery 太大(!)?我們需要這個輸出:<html><head></head><body>In the US we have 79082 reported cases with 76075 still active. 1864 recovered and 1143 casualties. The death ratio in the US is 0.01 at the moment, 0.02 is recovering. Last update at 2020/03/26. In the same time, we have 520755 total cases worldwide, with 23581 deaths and 122690 recovered, a 0.05/0.24 ratio.</body></html>*使用 JS 加載并包含遠程腳本 (index.php) 的 html 輸出應該可以解決問題。一個簡單的解決方案會有很大幫助。謝謝你!
查看完整描述

1 回答

?
holdtom

TA貢獻1805條經驗 獲得超10個贊

首先,您的Web服務器需要返回HTTP標頭

Access-Control-Allow-Origin,Access-Control-Allow-Origin: *允許所有網站訪問您的網絡服務器。然后,您可以使用 XMLHttpRequest:

function onReceive() {

? console.log(this.responseText);

}


const req = new XMLHttpRequest();

req.addEventListener("load", onReceive);

req.open("GET", "https://quarantine.country/coronavirus/cases/usa/");

req.send();

編輯:如果您不控制該quarantine.country網站,那么如果沒有他們的協作或您自己的網絡服務器,這是不可能的。


查看完整回答
反對 回復 2023-10-10
  • 1 回答
  • 0 關注
  • 188 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號