我怎样才能把我当前看到的网页(指javascript处理过的、可供用户查看的html文档网--类似于交互式AJAX网页)发送到服务器?
我可以按原样发送‘所有html元素的documnet对象母’到服务器吗?
发布于 2013-11-01 16:28:12
只需使用标准的js函数来获取'body‘元素,它就是innerHTML
var bodyHtml = document.getElementsByTagName('body')[0].innerHTML;然后您可以使用ajax请求服务器发送html。
发布于 2013-11-01 16:28:30
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<style type="text/css">
.contain-entire-page {
display: none;
}
</style>
</head>
<body>
<!-- us\sonawpa -->
<form class="submit-entire-page" action="demo.php" method="post">
<textarea class="contain-entire-page"></textarea>
</form>
<script type="text/javascript">
$(document).ready(function () {
var str = '<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml">';
str += $('html').html();
str += '</html>';
$('.contain-entire-page').val(str);
$('.submit-entire-page').submit();
});
</script>
</body>
</html>发布于 2013-11-01 16:23:28
如果要与网页中的web服务器交互,可以提交表单(向web应用程序发送web请求)或请求URL (从URL获取web请求)。
如果你想向服务器发送一些东西,你可以发布你想要的参数,当服务器收到请求时,它会执行一些功能并给你一个响应。帖子示例:
POST www.xxxx.com?name=asdf HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 97
Host: www.xxxx.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)回应是:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
Date: Thu, 31 Oct 2013 08:04:29 GMT
Transfer-Encoding: chunked
Connection: Keep-Alive
<html><body>Hello World</body></html>希望这能有所帮助。
https://stackoverflow.com/questions/19723077
复制相似问题