<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bobpeers -&#62; blog &#187; encoding</title>
	<atom:link href="http://blog.bobpeers.com/tag/encoding/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bobpeers.com</link>
	<description>Better late than never</description>
	<lastBuildDate>Fri, 24 Jun 2011 12:34:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>XMLHttp, UTF-8 and Foreign Characters</title>
		<link>http://blog.bobpeers.com/2009/06/05/xmlhttp-utf-8-and-foreign-characters/</link>
		<comments>http://blog.bobpeers.com/2009/06/05/xmlhttp-utf-8-and-foreign-characters/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 13:23:51 +0000</pubDate>
		<dc:creator>Bob Peers</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[xmlhttp]]></category>

		<guid isPermaLink="false">http://blog.bobpeers.com/2009/06/05/xmlhttp-utf-8-and-foreign-characters/</guid>
		<description><![CDATA[Living in Denmark I always have to develop sites that support the extra characters found in Danish names (&#248;,&#229;,&#230; plus Swedish, Norwegian and all the other European characters). For this reason I always use UTF-8 encoding to avoid and problems with displaying the characters. Just recently I had a major headache getting Firefox and IE6 [...]]]></description>
			<content:encoded><![CDATA[<p>Living in Denmark I always have to develop sites that support the extra characters found in Danish names (&oslash;,&aring;,&aelig; plus Swedish, Norwegian and all the other European characters). For this reason I always use <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8 encoding</a> to avoid and problems with displaying the characters.</p>
<p>Just recently I had a major headache getting Firefox and IE6 to insert the same data (sent via a XMLHttp GET request to an ASP page) into a database, the two browsers seemed to treat the same data differently so with one page Firefox would garble the characters while IE worked fine, while on another page the opposite was true.</p>
<p>This lead me to investigate exactly what is required to correctly send UTF-8 data to an ASP page and insert the characters into a database, fortunately I found the solution.</p>
<ol>
<li>In the Javascript code you use to send the GET request make sure you add the correct headers as shown here.
<pre>xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-Type", "text/html;charset=UTF-8");</pre>
</li>
<li>Encode the querystring using <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent">encodeURIComponent()</a> so a request looks like this.
<pre>xmlhttp.open("GET", "yourpage.asp?e="+encodeURIComponent(data));</pre>
</li>
<li>At the start of your ASP page add the following lines (the <a href="http://www.asp-dev.com/main.asp?page=96">CodePage=&#8217;65001&#8242; refers to UTF-8)</a>.
<pre>Response.CodePage = "65001"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"</pre>
</li>
<li>Finally make sure you save all your pages as UTF-8 (without the <a href="http://en.wikipedia.org/wiki/Byte-order_mark">Byte-order mark, or BOM</a>) and not ANSI. For this reason I recommend you do not use Notepad as it will add the BOM if used to save UTF-8 files. Use <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a> or some other program where you can choose the format to save.</li>
</ol>
<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;counturl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;count=none&amp;text=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;counturl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;count=none&amp;text=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;linkname=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;linkname=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" title="Evernote" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;linkname=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;linkname=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" title="Hotmail" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;linkname=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" title="WordPress" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;linkname=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;linkname=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;linkname=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F06%2F05%2Fxmlhttp-utf-8-and-foreign-characters%2F&amp;title=XMLHttp%2C%20UTF-8%20and%20Foreign%20Characters" id="wpa2a_2"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bobpeers.com/2009/06/05/xmlhttp-utf-8-and-foreign-characters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XMLHttp Character Encoding</title>
		<link>http://blog.bobpeers.com/2009/03/23/xmlhttp-character-encoding/</link>
		<comments>http://blog.bobpeers.com/2009/03/23/xmlhttp-character-encoding/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 11:52:12 +0000</pubDate>
		<dc:creator>Bob Peers</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[xmlhttp]]></category>

		<guid isPermaLink="false">http://blog.bobpeers.com/2009/03/23/xmlhttp-character-encoding/</guid>
		<description><![CDATA[I&#8217;ve been writing some new Intranet pages at work that include a searchable phone book that uses the XMLHttp object to return data in the background. Many of the names in the database include Scandinavian Characters like &#229;, &#248; and &#230; for example. IE always returned the correct results but if I searched for the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing some new Intranet pages at work that include a searchable phone book that uses the XMLHttp object to return data in the background.</p>
<p>Many of the names in the database include Scandinavian Characters like &aring;, &oslash; and &aelig; for example. IE always returned the correct results but if I searched for the Scandinavian characters using Firefox the search would return no results. It was clear that the SQL string being built in the ASP script was somehow mangling the characters so the query returned no data.</p>
<p>I checked the charcodes using JavaScript (using CharCode()) before the GET request was sent and IE and Firefox gave the same result. But then if I returned what the ASP script saw (using the asc function) it was clear that IE and Firefox disagreed at this point.</p>
<p>I assumed this was because the XMLHttp object in Firefox was using the wrong encoding so I added the following lines to force UTF-8 encoding (as used by the MS Access database phone book).</p>
<pre>xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-Type", "text/html;charset=uft-8")
</pre>
<p>Unfortunately this did nothing, but after a lot of testing and head scratching I finally discovered that my ASP script was saved in ANSI format. As soon as I converted the script to UTF-8 and saved it everything worked perfectly in Firefox.</p>
<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;counturl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;count=none&amp;text=XMLHttp%20Character%20Encoding" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;counturl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;count=none&amp;text=XMLHttp%20Character%20Encoding" scrolling="no" style="border:none;overflow:hidden;width:55px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;linkname=XMLHttp%20Character%20Encoding" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;linkname=XMLHttp%20Character%20Encoding" title="Evernote" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;linkname=XMLHttp%20Character%20Encoding" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_hotmail" href="http://www.addtoany.com/add_to/hotmail?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;linkname=XMLHttp%20Character%20Encoding" title="Hotmail" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/live.png" width="16" height="16" alt="Hotmail"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;linkname=XMLHttp%20Character%20Encoding" title="WordPress" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;linkname=XMLHttp%20Character%20Encoding" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;linkname=XMLHttp%20Character%20Encoding" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;linkname=XMLHttp%20Character%20Encoding" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.bobpeers.com%2F2009%2F03%2F23%2Fxmlhttp-character-encoding%2F&amp;title=XMLHttp%20Character%20Encoding" id="wpa2a_4"><img src="http://blog.bobpeers.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bobpeers.com/2009/03/23/xmlhttp-character-encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

