[英]How to show html code from javascript var?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
var div = $.get( "https://m.vk.com/");
</script>
</head>
<body>
<script>
str = JSON.stringify(div);
window.alert(str);
</script>
</body>
</html>
此代码打印我的文本:“readystate”..我需要显示网站的完整 html 代码...我该怎么做?
$.get
返回一个 promise (它是异步调用),所以你需要:
var promise = $.get( "https://m.vk.com/");
promise.then(html => {
window.alert(html);
});
NOTE: In the recent version of jQuery (not sure from which version) promises are compatible with native Promise objects (type A promise specification), so they have then
method even that the jQuery docs say otherwise.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.