For a web administration interface that we have developed here on Wohill we are currently using for the AJAX functionality when saving and getting information from the database back and forth to the interface.
We are using as the text editor when creating some kind of content to get a more desktop feeling.
When receiving information for a page which contains name, title, image, date and text, an asynchronous request is sent in the backround to get the data from the database. When the data has been queried from the database and we have a resultset, I am building a small JSON object with this information which is then sent back to the admin interface.
When receiving this information on the client (admin interface) side we need to decode the json object to be able to use all the pieces of information separately.
This workflow works fine in Firefox and Google Chrome but for Internet Explorer 7 (which is the only version of IE I have tested it on) it doesn't. The problem is when the text body (which is html) contains line break carrige return. Invincible characters in the string like
'\r' and
'\n' is what causes the error
"Unterminated String Constant".
The JSON object that is built before sent to the client looks something like this:
| $json = '{"status":1,"header":"' . $row['header'] . '","subHeader":"' . $row['subHeader'] . '","image":"' . $row['img'] . '","textbody":"' . $row['textbody'] . '"}'; |
And it is decoded using Ext's decoding function:
var obj = Ext.decode(respStr); alert(obj.header); alert(obj.subHeader); // etc. |
To make the fix for the error message in Internet Explorer; work with the response string a bit before decoding it and you will get rid of the error message. What happens is that all line break carrige returns are escaped:
var re = /\n/g; respStr = respStr.replace(re, '\\n'); re = /\r/g; respStr = respStr.replace(re, '\\r'); var obj = Ext.decode(respStr); alert(obj.header); alert(obj.subHeader); // etc. |
Here is some on this problem. But in this case they had problem with IE 8 and not 7.