Solved

post HTML code

Posted on 2013-05-17
1
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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…
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…

705 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