国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

給定URL,以字符串形式返回HTML內容Javascript功能

瀏覽:98日期:2024-05-09 15:38:44
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解決給定URL,以字符串形式返回HTML內容Javascript功能?

您需要在readystate == 4時返回,例如

function httpGet(theUrl){ if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safarixmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); } xmlhttp.onreadystatechange=function() {if (xmlhttp.readyState==4 && xmlhttp.status==200){ return xmlhttp.responseText;} } xmlhttp.open('GET', theUrl, false ); xmlhttp.send(); }解決方法

我想編寫一個JavaScript函數,該函數以給定URL的字符串形式返回HTML內容。我在Stackoverflow上找到了類似的答案。

但是,似乎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>

標簽: JavaScript
主站蜘蛛池模板: 保康县| 汶上县| 满城县| 阿克苏市| 甘泉县| 嘉义县| 阳东县| 原阳县| 扎囊县| 炉霍县| 泗洪县| 永和县| 德州市| 阿荣旗| 罗定市| 抚远县| 奇台县| 辉南县| 宣威市| 五河县| 新建县| 南江县| 门头沟区| 泰宁县| 赤壁市| 中宁县| 金堂县| 南充市| 象州县| 普陀区| 恭城| 米泉市| 金湖县| 汽车| 休宁县| 筠连县| 贵德县| 巴林右旗| 曲阜市| 宜兰县| 五大连池市|