我想寫一個javascript函數,該函數返回HTML內容作爲給定函數的URL的字符串。我在Stackoverflow上找到了類似的答案。將HTML內容作爲字符串返回給定URL。 Javascript函數
我想用this answer來解決我的問題。
但是,好像document.write()
不寫任何東西。當我加載頁面時,我得到一個空白屏幕。
<html>
<head>
</head>
<body>
<script type="text/JavaScript">
function httpGet(theUrl)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, false);
xmlHttp.send(null);
return xmlHttp.responseText;
}
document.write(httpGet("https://stackoverflow.com/"));
</script>
</body>
</html>
使用.innerHT ML,而不是document.write。 –
你的意思是像'httpGet(「http://stackoverflow.com/」).innerHTML;'?這也加載了一個空白頁。 –
下面的答案描述你需要什麼。 –