What I am trying to do is to display data coming from a mysql database into a inside a form. I get the data through an ajax call to my db manager that retrieves the data.
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
` $('.btn-group#couleur > button').click(function(){
$.ajaxSetup({
async:false,
scriptCharset: "iso-8859-1",
contentType:"application/json; charset=iso-8859-1"
});`
</li>
`
CREATE TABLE IF NOT EXISTS `pays` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`pays` varchar(30) COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci ;
`
`<select class="span8" name="pays">
<option value="11">Chili</option>
<option value="5">Espagne</option>
<option value="4">�tats-Unis</option>
<option value="2">France</option>
<option value="3">Gr�ce</option>
<option value="6">Italie</option>
<option value="9">Nouvelle-Z�lande</option>
<option value="7">Portugal</option>
</select>`
Any guess as to what I might be doing wrong ?
Your encoding from the database and the HTML output do not match: you tell your browser that you write UTF-8 but fetch latin1/iso-8859-1 from your database and write that directly to your <option>s fields. Ain’t gonna work.
You have to use a conversion function like iconv(), which is probably done best in the function that fetches data from your database and pushes it to your Ajax call. Since you didn’t tell what the language is, you have to look that up yourself.
Note: specifying contentType:”application/json; charset=utf-8″ to your Ajax call will not automagically transform the encoding, unless you have a very smart Ajax call…