358 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Jobs | Twitter | Bookmarks | Pods | Forum | Blogs | Search | myPL | About 
 
Latest 7 Posts
Add blog updates to Twitter and Facebook easily
Wed, Sep 1st 2010 29
A cartoon dog
Sun, Aug 29th 2010 43
More wild strawberries
Sat, Aug 28th 2010 49
Search all your Salesforce code
Wed, Aug 25th 2010 39
A facial expression
Sun, Aug 22nd 2010 50
The American Cocker Spaniel Max
Sun, Aug 22nd 2010 26
Replacing characters with Notepad++
Wed, Aug 18th 2010 114
Top 10
"Unterminated String Constant" when decoding the JSON object in Internet Explorer 7
Wed, Jul 8th 2009 407
When decoding a JSON string to a JSON object in Ext Core 3.0
Wed, May 20th 2009 382
Simple Ajax functionality with Ext.js and Domino
Wed, Jan 27th 2010 234
A web service consumer example
Mon, Dec 15th 2008 209
Get selected document from embedded view
Fri, Aug 1st 2008 206
Handling multiple values for checkboxes
Wed, Oct 1st 2008 200
How to get web data into excel
Wed, Nov 19th 2008 195
Simple JavaScript for opening a (modal) window
Fri, Aug 15th 2008 187
Which JavaScript Framework do you use?
Wed, May 5th 2010 178
Query an SQL-database from Java
Mon, Sep 22nd 2008 173


"Unterminated String Constant" when decoding the JSON object in Internet Explorer 7
Niklas Waller    

For a web administration interface that we have developed here on Wohill we are currently using Ext JS for the AJAX functionality when saving and getting information from the database back and forth to the interface.
We are using TinyMCE 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 more info on this problem. But in this case they had problem with IE 8 and not 7.




---------------------
http://www.wohill.com/design/534/%22Unterminated-String-Constant%22-when-decoding-the-JSON-object-in-Internet-Explorer-7.html
Jul 08, 2009
420 hits



Recent Blog Posts
29


Add blog updates to Twitter and Facebook easily
Wed, Sep 1st 2010 8:28p   Niklas Waller
I have earlier tried to do this myself and just got tired of it. Now I found an easy way that has probably been around for a while. Maybe it could be useful for you too. This assumes you have an RSS-feed, which you probably do. brbrbFirst get the blog updates to Twitter:/bbr1. Get an account at a href="http://twitterfeed.com" target="_blank" class="comments"Twitterfeed/abr2. Create new feedbr3. Under 'Advanced Settings', add '#fb' as Post Suffixbr3. Goto step 2 and authenticate with your Twitter [read] Keywords: application facebook profile twitter
43


A cartoon dog
Sun, Aug 29th 2010 8:30p   Randolph Guy
I told you about our summer-guest #8211; Max - The American Cocker-Spaniel. He was a great wee friend and lots of fun. brbrI sat down here today after going to Toy Story 3 and sketched away on some work I have to get done. I then, as usual, got going on some drafts and some extra sketches. This time I was thinking of Max #8211; the dog - and thought it would be nice to draw a few lines that looked like a little dog-head.brbrNow I really have to get back to the stuff for tomorrow!brbrbr /br /img [read] Keywords:
49


More wild strawberries
Sat, Aug 28th 2010 8:29p   Niklas Waller
In the summertime when you are a kid in Sweden it is common to pick wild strawberries and put them on a straw. This is what all kids did when we visited my mother and uncle this summer.brbrI like the variation of sharpness in this photo. It goes from blurred to sharp and then back to blurred again in a nice way I think.brbrAnd wild strawberries really is summer to me!br /br /img src='http://www.wohill.com/images/wild_strawberries.jpg' / pa href="http://feedads.g.doubleclick.net/~a/I4g9C7TSFLDdHp [read] Keywords:
39


Search all your Salesforce code
Wed, Aug 25th 2010 8:30p   Niklas Waller
If you would like to search all code in an Eclipse Salesforce project or perhaps several projects this is how it is quickly done.brbr1. Click on 'Search' in the Menubrbr2. Click on 'File...'brbr3. By default all classes are chosen in the search scope. If you want to add Triggers, click on 'Choose' and scroll down to '*.trigger' and tick that checkbox. Click 'Ok'.brbr4. You can choose to search all projects in the workspace. Selected by default in the Scope section. Or you can narrow down the sea [read] Keywords: eclipse workspace
50


A facial expression
Sun, Aug 22nd 2010 8:31p   Randolph Guy
An expression in a face shows a lot#8230; Or sometimes nothing#8230; brThe best is when you need to show as little as possible and yet it is totally clear what you are feeling.brbrThis design is a bit more of a thinking dude or expressive expression. It gives a feeling that you as the person meeting this face for the first time have to interpret what it is saying. With just a few lines and bends #8211; here is an expressive feeling for you.brbr /br /img src='http://www.wohill.com/images/Facial_e [read] Keywords:
26


The American Cocker Spaniel Max
Sun, Aug 22nd 2010 10:30a   Randolph Guy
This summer we had a little friend staying for the summer. His name is Max and he is a little black dog (American Cocker Spaniel). He is a happy little fellow that hanged out with us everywhere. We have been lots out in the archipelago and he has been with us every day #8211; all over the place. He seemed to love going out in the boat and hopping ashore to visit our home #8211; and we showed him where we live and what we do.brbrHis own family had a vacation in Turkey this summer and could not br [read] Keywords:
114


Replacing characters with Notepad++
Wed, Aug 18th 2010 8:28p   Niklas Waller
Notepad++ is an excellent tool for text processing of different kinds.brbrLet's assume you have a CSV-file on this form:brtable class="codeTable"tbodytrtdcode"FIELD 1 HEADER","FIELD 2 HEADER","FIELD 3 HEADER"br"row 1 field 1","row 1 field 2","row 1 field 3"br"row 2 field 1","row 2 field 2","row 2 field 3"br"row 3 field 1","row 3 field 2","row 3 field 3"/code/td/tr/tbody/tablebrAnd you want it on this form:brtable class="codeTable"tbodytrtdcodeFIELD 1 HEADER;FIELD 2 HEADER;FIELD 3 HEADERbrrow 1 f [read] Keywords: mysql




45


A great trip to Egypt
Sun, Aug 15th 2010 8:32p   Randolph Guy
Last Christmas we all where in Egypt. Really interesting trip I must say. I have written a few things about our trip before as you might have noticed. I also visited the Pyramids and the Egyptian Museum. There one could see lots of great designs and styles of design from ancient times. I must say that a lot of today#8217;s design can have been inspired by the old Egyptians.brbrHere I have mad a cartoon or tattoo-like #8221;Pharaoh#8221;.brbr /br /img src='http://www.wohill.com/images/Pharaoh_car [read] Keywords:
78


A female mallard duck
Sat, Aug 14th 2010 8:27p   Niklas Waller
In places where people live, Mallards are not very shy. They often come closer to see if there is something to eat. Therefore this isn't a rare photo in any way, but I always like getting them close since animals are beautiful. brbrThe male has a green head and is more colorful as males often are in the world of animals and the female is mostly brown. But she got some color on the back side at least.br /br /img src='http://www.wohill.com/images/mallard_duck_female.jpg' / pa href="http://feedads. [read] Keywords:
86


Drag and drop with Google Chrome
Wed, Aug 11th 2010 8:27p   Niklas Waller
In the spring we learned that it is now possible to a href="http://gmailblog.blogspot.com/2010/04/drag-and-drop-attachments-onto-messages.html" target="_blank" class="comments"drag a file onto a message/a as an attachment. You just drag it from you explorer or desktop and put it in the drop file area. brbrIt is also became possible to a href="http://gmailblog.blogspot.com/2010/05/drag-images-into-messages.html" target="_blank" class="comments"drag an image into a message/a to make it appear in t [read] Keywords: desktop google mac




Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - FAQ - Mobile Edition