360 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Jobs | Twitter | Bookmarks | Pods | Forum | Blogs | Search | myPL | About 
 
Latest 7 Posts
This message will self-destruct
Wed, Mar 17th 2010 55
What happens on a Visualforce page with a controller
Wed, Mar 10th 2010 22
Modifying the Salesforce Partner Edit page
Wed, Mar 3rd 2010 32
Enabling your Google profile and follow other Buzz users
Wed, Feb 24th 2010 18
List has no rows for assignement to SObject
Wed, Feb 17th 2010 23
Create and save a PDF for any website for free
Wed, Feb 10th 2010 81
Google Browser Size for Wohill
Wed, Feb 3rd 2010 48
Top 10
"Unterminated String Constant" when decoding the JSON object in Internet Explorer 7
Wed, Jul 8th 2009 103
Handling multiple values for checkboxes
Wed, Oct 1st 2008 91
Simple JavaScript for opening a (modal) window
Fri, Aug 15th 2008 89
How to get web data into excel
Wed, Nov 19th 2008 84
Create and save a PDF for any website for free
Wed, Feb 10th 2010 81
Simple Ajax functionality with Ext.js and Domino
Wed, Jan 27th 2010 71
Query an SQL-database from Java
Mon, Sep 22nd 2008 67
Where to change the Salesforce API version of a class
Wed, Dec 16th 2009 59
When decoding a JSON string to a JSON object in Ext Core 3.0
Wed, May 20th 2009 56
The Lotus Notes combobox generates HTML differently for IE and Firefox
Wed, Dec 9th 2009 55


"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
116 hits



Recent Blog Posts
55


This message will self-destruct
Wed, Mar 17th 2010 7:24p   Niklas Waller
I found this odd but a bit cool service called This Message Will Self-Destruct on the swedish blog Arwengrim. The idea is that you create a message which can be set with a password (optional). After creating it you get an URL where to reach it. You provide this URL to the receiver via email, mouth or something else and once the receiver accesses it it can only be read that one time. It is at the very same time deleted from the database. Creating... Receiving... Feels a bit like Mission: I [read] Keywords: database email password
22


What happens on a Visualforce page with a controller
Wed, Mar 10th 2010 6:27p   Niklas Waller
I found a good page in the Eclipse Help pages for Force.com which explains the architecture of a controller extension and custom controller. These are the steps (in general) that happens when a VIsualforce page is requested, loaded, managed and closed. 1. User requests a page ONLOAD: 2. The constructors are called for a possible associated controller or controller extension. 3. The assignTo attributes on any custom components on the page are executed 4. Expressions are evaluated. 5. The action [read] Keywords: eclipse
32


Modifying the Salesforce Partner Edit page
Wed, Mar 3rd 2010 6:28p   Niklas Waller
We got a request to modify the page that opens when you want to add a partner for an Opportunity. Sounds like an easy task to start with. However it turns out to be a bit difficult. The page is a standard page built into the application and can not be changed. The obvious option would then be to create your own Visualforce page instead and override the New button on the Opportunity related list for Partner to point to this Visualforce page instead. However that is not possible either. You can [read] Keywords: application
18


Enabling your Google profile and follow other Buzz users
Wed, Feb 24th 2010 6:24p   Niklas Waller
Since Google Buzz started there is suddenly a need for managing your Google profile. Your profile is more or less visible and clickable depending on how well you have entered your personal information. You have to open your profile and add information and also (optional) choose a username for your profile URL (otherwise it is just a long number). Get your profile by logging into Google at www.google.com and click on 'Edit profile'. You can also goto http://www.google.com/profiles/ and search for [read] Keywords: google profile
23


List has no rows for assignement to SObject
Wed, Feb 17th 2010 6:24p   Niklas Waller
I was modifying a test class for a trigger when I bumped into this error message - "List has no rows for assignement to SObject". This means that an object instance that is to be assigned a value from a SOQL query does not get assigned, i.e. the SOQL query return no value. My case was something like this: Opportunity opp = [select id, StageName where id = :someId] If the SOQL query for some reason would not a return a result row the error message would be raised. A way to solve this is to assig [read] Keywords:
81


Create and save a PDF for any website for free
Wed, Feb 10th 2010 6:24p   Niklas Waller
Now you can create and save a PDF for any website for free with PDFmyURL.com either by typing in the url by hand on the site or by calling the website url with querystring parameters via a link or directly in the address field of the web browser. This link: Download a random wohill page as a PDF would look like this in HTML: Download a random wohill page as a PDF As you can see the whole blog framework with one page is created as a PDF. It could be interesting here to point to just the blog e [read] Keywords:




48


Google Browser Size for Wohill
Wed, Feb 3rd 2010 6:27p   Niklas Waller
Interesting tool. I am not sure if I like it or not. It doesn't look too good for most sites though. I was aware that some people still uses a low resolution but I didn't think it was this bad. However I interpret it the way that they have taken into account also parameters like when visitors don't have their browser window expanded to the maximum or when visiting with a mobile device (and the site is not specifically enabled fior that). Something to consider anyway. Check it out for your ow [read] Keywords: google mobile
45


Creating an attachment instance in a testMethod
Wed, Jan 27th 2010 6:26p   Niklas Waller
If you have created an Apex class which uses Attachments in some way you might need to create Attachments as test data for the testMethod in order to get the coverage to be able to deploy. The attachment has three required fields: Body, Name and ParentId But how is the body, which is the attachment, created programmatically? I found this solution in a Salesforce community and also later on the Salesforce blog: PageReference pdf = Page.testPDF; pdf.getParameters().put('p','p'); pdf.setRed [read] Keywords: community
14


SOQL vs SQL
Wed, Jan 27th 2010 11:06a   Niklas Waller
SOQL (Salesforce Object Query Language) is the language used in salesforce when writing Apex classes for example to retrieve sets of data. SQL (Structured Query Language) is the language for managing data in relational database systems. The two query languages are very similar but differ in different distinctive ways. In general SOQL is not as powerful as SQL and don't have all the same functions. Here are three of the more imporant differences as bullet points: - SOQL is only used to retriev [read] Keywords: database linking sql
71


Simple Ajax functionality with Ext.js and Domino
Wed, Jan 27th 2010 11:06a   Niklas Waller
Here is a simple example of how to easily achieve Ajax-functionality with Domino and Ext.js. The idea is to, from a page that is opened in a web browser, call a Domino agent asynchronously and in the background to do some work and to provide feedback on it. The page is then updated when the work is done. 1. Download the Ext core (http://www.extjs.com/products/extcore/download.php). This is a JavaScript library that among others contains functionality that can be used to achieve Ajax functionali [read] Keywords: agent domino lotus notes notes client ajax database javascript server




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