Skip to main content
Inspiring
December 9, 2010
Answered

AJAX response - escaped html

  • December 9, 2010
  • 1 reply
  • 618 views

Hi Folks,

I'm using BBC's glow to make an ajax post to a coldfusion page.

It works fine apart from displaying the results in a div with all the html escaped.

Does anyone know how I can display the results as html?

Is there a coldfusion tag/ function that turns special chars into html?

Many thanks


<div id="alert">

&lt;table width="100%" border="0" cellspacing="5" cellpadding="5"&gt;
  &lt;tr&gt;
    &lt;td&gt;Name&lt;/td&gt;
    &lt;td&gt;Lead&lt;/td&gt;
  &lt;/tr&gt;

  &lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;

    &lt;td&gt;ABDUL KADIR&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Abigail Clinton&lt;/td&gt;

    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Adrienne Parker&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;

  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Aileen Makohon&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;

  &lt;tr&gt;
    &lt;td&gt;Aimee Garbett&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;

    &lt;td&gt;Alison Boughey&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Alison Durman&lt;/td&gt;

    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Alison Hodgson&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;

  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Amy Harrison&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;

  &lt;tr&gt;
    &lt;td&gt;Matthew Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;

    &lt;td&gt;Clare Neill&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Lynne Thompson&lt;/td&gt;

    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Clare Neill&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;

  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Amanda Harris&lt;/td&gt;
    &lt;td&gt;0&lt;/td&gt;
  &lt;/tr&gt;

  &lt;tr&gt;
    &lt;td&gt;Amanda Harris&lt;/td&gt;
    &lt;td&gt;0&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;

    &lt;td&gt;Amanda Harris&lt;/td&gt;
    &lt;td&gt;0&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Amanda Harris&lt;/td&gt;

    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Amanda Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;

  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Matthew Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;

  &lt;tr&gt;
    &lt;td&gt;Matthew Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;

    &lt;td&gt;Matthew Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Matthew Harris&lt;/td&gt;

    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Matthew Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;

  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Matthew Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;

  &lt;tr&gt;
    &lt;td&gt;Matthew Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;

    &lt;td&gt;Matthew Harris&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Matthew Harris&lt;/td&gt;

    &lt;td&gt;1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Amanda Harris&lt;/td&gt;
    &lt;td&gt;0&lt;/td&gt;

  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Amy Harrison&lt;/td&gt;
    &lt;td&gt;0&lt;/td&gt;
  &lt;/tr&gt;

  &lt;tr&gt;
    &lt;td&gt;Amanda Harris&lt;/td&gt;
    &lt;td&gt;0&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;

    &lt;td&gt;Amanda Harris&lt;/td&gt;
    &lt;td&gt;0&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt; </div>


This topic has been closed for replies.
Correct answer Fernis

Without drilling down to the problem - why the characters show up in escaped format, I'll just answer the one question:

No, there is not a function in ColdFusion which unescapes escaped HTML strings. Neither has anyone published such function on cflib.org.

But unescaping is easy with ReplaceList() function. Just have the most typical/probably escaped and unescaped strings in the argument lists, and you'll have yourself a function.

Something like this:

<cfscript>

public function HtmlUnescape(htmlstring)

{

     return replaceList(arguments.htmlstring,"&gt;,&lt;",">,<");

     //add any other probable special characters and their encodings also to the list

}

</cfscript>

<cfsavecontent variable="test">

&lt;table width="100%" border="0" cellspacing="5" cellpadding="5"&gt;

</cfsavecontent>

<cfoutput>

original: #htmlcodeformat(test)#

<br>

unescaped: #htmlcodeformat(HtmlUnescape(test))#

</cfoutput>

-Fernis

1 reply

Fernis
FernisCorrect answer
Inspiring
December 10, 2010

Without drilling down to the problem - why the characters show up in escaped format, I'll just answer the one question:

No, there is not a function in ColdFusion which unescapes escaped HTML strings. Neither has anyone published such function on cflib.org.

But unescaping is easy with ReplaceList() function. Just have the most typical/probably escaped and unescaped strings in the argument lists, and you'll have yourself a function.

Something like this:

<cfscript>

public function HtmlUnescape(htmlstring)

{

     return replaceList(arguments.htmlstring,"&gt;,&lt;",">,<");

     //add any other probable special characters and their encodings also to the list

}

</cfscript>

<cfsavecontent variable="test">

&lt;table width="100%" border="0" cellspacing="5" cellpadding="5"&gt;

</cfsavecontent>

<cfoutput>

original: #htmlcodeformat(test)#

<br>

unescaped: #htmlcodeformat(HtmlUnescape(test))#

</cfoutput>

-Fernis

matthiscoAuthor
Inspiring
December 10, 2010

Thanks very much for your reply