How to send current HTML document of current web page to server?

how can I send my currently viewed web page (means javascript processed html documnet processed for user view - AJAX interactive web page view) to the server?

Can I send the "documnet object material of all html elements" to the server as it is?

+4
source share
3 answers

Just use the standard js function to get the body element and innerHTML

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

then you can use ajax request to the server to send html

+1
source
<!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>
0
source

Nice to meet you :) each of them sometimes happens. According to your question, if you want to interact with the web server inside the web page, you can send the form (POST web request to the web application) or request the URL (get the web request from the URL) if you want to send something to the server, you can POST the parameters you want, and when the server receives the request, it will perform some functions and give you an answer. POST example:

    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)

answer:

    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>

I hope for this help.

-1
source

All Articles