• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

post HTML code

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
tonelm54
Asked:
tonelm54
1 Solution
 
Ioannis ParaskevopoulosCommented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now