cfmalik
asked on
Display HTML formatted text in div after retrieving from DB via AJAX
Hi Experts,
I've probably done the hardest part of my spec but mind's boggled by something very strange. I'll explain:
I have a simple cfm page with a div and a textarea, plus AJAX code. The idea is when a user type something into the text area and presses 'add' it does so through AJAX, and then displays the results in the div's innerhtml.
All this works fine.
The problem is when i update div with a new note, i want to add some HTML (<br> & <font>) around parts of the text.
This gets updated to the database fine but when i get it back and display it in the div, it displays it with all the HTML tags around it! ie: <br> will be displayed as <br> not an actual line break!
The weird thing is, when i run this on my machine at home, using 'longtext' data type in MYSQL it works fine. But when i run it at work, storing the data in a 'ntext' field on MSSQL, it displays the HTML code!
Please can some one tell me how to ensure the HTML returned from the db is displayed as HTML?
When i put <pre> tags around it, it just displays as pure text!
Do i need to encode/decode? serialize/deserialize?
Please give code as examples and tell me hy it would work at hme but not work?
Thanks a million!
ajaxtext.cfm.txt
cfresponse.cfm.txt
notes.cfc.txt
I've probably done the hardest part of my spec but mind's boggled by something very strange. I'll explain:
I have a simple cfm page with a div and a textarea, plus AJAX code. The idea is when a user type something into the text area and presses 'add' it does so through AJAX, and then displays the results in the div's innerhtml.
All this works fine.
The problem is when i update div with a new note, i want to add some HTML (<br> & <font>) around parts of the text.
This gets updated to the database fine but when i get it back and display it in the div, it displays it with all the HTML tags around it! ie: <br> will be displayed as <br> not an actual line break!
The weird thing is, when i run this on my machine at home, using 'longtext' data type in MYSQL it works fine. But when i run it at work, storing the data in a 'ntext' field on MSSQL, it displays the HTML code!
Please can some one tell me how to ensure the HTML returned from the db is displayed as HTML?
When i put <pre> tags around it, it just displays as pure text!
Do i need to encode/decode? serialize/deserialize?
Please give code as examples and tell me hy it would work at hme but not work?
Thanks a million!
ajaxtext.cfm.txt
cfresponse.cfm.txt
notes.cfc.txt
when you view the html source are you seeing <br> or are you seeing & lt; br & gt; ?What is actually stored in the DB?Is ntext not binary? I have no idea if this would have affect on your data (in relation to your problem). Have you tried nvarchar or even varchar?
?
ASKER
this is how it is saving in db:
hiii (Modified by: Test Comms on 3/11/2008 17:10:43) <br>hi again (Modified by: Test Comms on 3/11/2008 17:11:4)
and this is how it is also displaying on the page, not html escaped (& lt; br & gt;)
How can i ensure the <br> is actually a line break?
hiii (Modified by: Test Comms on 3/11/2008 17:10:43) <br>hi again (Modified by: Test Comms on 3/11/2008 17:11:4)
and this is how it is also displaying on the page, not html escaped (& lt; br & gt;)
How can i ensure the <br> is actually a line break?
ASKER
sorry, just checked again and it saves in db as & lt; br & gt;
but when the variable is put in between <cfoutput> tags, it shows <br>
but when the variable is put in between <cfoutput> tags, it shows <br>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.