如何從遠程網站(遠程 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網站,那么如果沒有他們的協作或您自己的網絡服務器,這是不可能的。
- 1 回答
- 0 關注
- 188 瀏覽
添加回答
舉報
0/150
提交
取消