2013-11-01 27 views
4

我怎样才能发送我目前看到的网页(意味着JavaScript处理操作HTML documnet用户的视图 - 种交互式AJAX网页)到服务器?如何将当前网页的整个HTML文档发送到服务器?

我可以将'所有html元素的documnet对象母亲'发送到服务器吗?

+0

你的问题应该是更具体的了解你试图达到什么目标,但你可以得到所有的标记,如果你有jquery http://jsfiddle.net/MUkGe/但我实际上没有看到这个目的。 –

+3

通过使用'document.documentElement.innerHTML',您可以获得''标签之间的所有内容。 – Vishal

+0

哦神圣的神!谢谢! – KOLOKOLOK

回答

-1

很高兴认识你:) 有时候每个人都是一个noob。 对于您的问题,如果您想要与网页中的Web服务器交互,可以提交表单(POST请求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> 

希望这有助于。

1

只需使用标准js函数用于获取“体”元素,它的innerHTML

var bodyHtml = document.getElementsByTagName('body')[0].innerHTML; 

,那么你可以使用Ajax请求到服务器发送HTML

0
<!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> 
相关问题