Show-n-Tell Thursday

Character encoding in an Ajax LotusScript agent

I know it's Monday, but I thought I'd share this with you anyway.

So, most people know that you can control the content-type in an agent called by an Ajax request (or any type of agent for that matter) by using this line:

print |content-type: text/plain|

which will result in plain text being sento to the browser, of course you can also send HTML, XML, JSON or any other content type that you so choose.

What you may not have known is that you can also control the charset property of the response. Why would you want to do this? Well if you have an agent that returns high number Ascii characters such as é or ö then by default they will be returned to the Ajax request as non-printing characters. But if you use this line in your agent then they will be transferred to your browser correctly:

print |content-type: text/plain; charset=utf-8|

So my recommendation is that for every agent that you write where you would have just set the content-type, just take that extra few seconds to define the character set as well to save yourself trouble down the line.

You may well take from this, that I have just been burned by this very issue, and you may well be correct. Did I mention that version 1.3 of IdeaJam will be released very shortly ;-)