Solved

post HTML code

Posted on 2013-05-17
1
302 Views
Last Modified: 2013-06-03
I'm trying to offer a feedback function on a website I'm working on, but want to be able to capture the current HTML on the screen, so wrote:-

    function htmlEscape(str) {
        return String(str).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    }


    function commentPage() {
        $.ajax({
          type: "POST",
          url: 'feedback.php',
          data: {     'txtHTML'       : htmlEscape(document.documentElement.outerHTML) },
          success: function(retHtml, textStatus) {
                    alert(retHtml);
                    },
          error: function (xhr, textStatus, errorThrown) {
                    showDialog("Failed - " + errorThrown ? errorThrown : xhr.status);
                    }
          });

Open in new window


But all I get back is 'Forbidden'.

If I replace the line
htmlEscape(document.documentElement.outerHTML)

Open in new window

with
"Test"

Open in new window

The the "Test" is passed successfully as a post.

If I debug the line:-
htmlEscape(document.documentElement.outerHTML)

Open in new window


Then I can see the escaped html code fine, its just not submitting.

Can anyone advise what is going wrong?

Thank you
0
Comment
Question by:tonelm54
1 Comment
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 500 total points
ID: 39176764
Hi,

Can you try the following?

    function htmlEscape(str) {
        return String(str).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    }


    function commentPage() {
        var htmltext;
        htmltext=htmlEscape(document.documentElement.outerHTML);
       
        $.ajax({
          type: "POST",
          url: 'feedback.php',
          data: {     'txtHTML'       : htmltext },
          success: function(retHtml, textStatus) {
                    alert(retHtml);
                    },
          error: function (xhr, textStatus, errorThrown) {
                    showDialog("Failed - " + errorThrown ? errorThrown : xhr.status);
                    }
          });

Open in new window


Giannis
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question