Quantcast
Channel: James Allen's Coldfusion and Internet Technology Blog - ColdFusion
Viewing all articles
Browse latest Browse all 9

Character set problems with Ajax requests when using serializeJSON

$
0
0

Just a quick post while I'm thinking about it and for future reference about character set issues you can get when making an Ajax request and getting JSON back from ColdFusion via serializeJSON.

I am working on an item selection tool that takes a search term, submits it via the JQuery ajax method and ColdFusion does a d/b search and returns the results as JSON via the excellent serializeJSON method.

I noticed that the results coming back had numerous odd looking characters where the character being sent back wasn't rendering properly on the front-end. I have seen this many times before and it's usually the character set being used that is the issue.

It was here as well, but the fix wasn't what I expected. I thought throwing in a:

{code}<cfprocessingdirective pageencoding="utf-8">{/code}

..on the view which returns the JSON would do the trick but it didn't in this case.

The fix was to place this at the top of the view:

{code}<cfcontent type="application/json;charset=utf-8">{/code}

The cfcontent tag was already there as I needed to tell CF what format I wanted to return but the extra charset parameter did the trick on fixing the character rendering problems.

A useful thing to remember when dealing with Ajax calls.


Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles





Latest Images