Solved

post HTML code

Posted on 2013-05-17
1
295 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
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…

810 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