Solved

post HTML code

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn how to dynamically set the form action using jQuery.
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)

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now