问题
Im working with jquery and ASP, and have an SQL database from which I get, using the function $.getJSON(), some descriptions in spanish with "acentos" and "tildes" (á, é, í, ó, ú, ñ, etc.).
With Chrome 4 and FireFox is working fine. The problem is with IE8: with some particular query, it hangs without getting the result back. If I replace all "ó" with "o" using IE, the same resultset works perfect, so I know the problem is with the "acentos" (ó).
Im setting the ajax call with this code:
$.ajaxSetup({'beforeSend' : function(xhr) {
if (xhr.overrideMimeType) {
//FF & Chrome
xhr.overrideMimeType('text/html; charset=iso-8859-1');
}else {
//IE8
//I tried everything here:
//xhr = new ActiveXObject("Microsoft.XMLHTTP");
//var obj = new ActiveXObject("MSXML2.XMLHTTP.3.0");
//xhr = new ActiveXObject("Msxml2.XMLHTTP");
//and get ERROR with IE8 in this line:
xhr.setRequestHeader('Content-type', 'text/html; charset=iso-8859-1');
}
}
});
And then, the call to getJSON() to get the descriptions with "acentos" is like this:
function showDialog(idCriterio, codAplica, descTema){
$("#dialog-modal").html("Buscando Datos...");//getting data...
$.getJSON("generarJSONTipos.asp", { idCriterio: idCriterio, codAplica: codAplica},
//callback function
function(data){
var textoDialogo;
textoDialogo= "";
$("#dialog-modal").html("<span class='tituloOpcion'>"+descTema+"</span><br><br>");
for(i=0;i<data.length;i++) {
//tomo el html actual
textoDialogo = $("#dialog-modal").html();
//le apendo la descripcion del elemento del array
$("#dialog-modal").html(textoDialogo + data[i].descripcion + "<br>");
}//end for
}//end callback
);//end getJSON
$("#dialog-modal").dialog({
height: 300,
width:450,
modal: true
});
$("#dialog-modal").dialog('open');
}
Any hints will be apreciated. I have googled for days, without getting to the answer to this question... :P
Thanks in advance, Ignacio (La Plata, Argentina)
回答1:
The answer was very simple, but took me several days to discover. I share it here, for everyone who has the same problem.
The solution is to specify the type of content right in the response object (ASP) or with the header function in PHP:
ASP
Response.ContentType="text/html; charset=iso-8859-1"
PHP
header("text/html; charset=iso-8859-1");
This must be the first line of the response (I think), on the file that generates the JSON objects. Any comments will be appreciated.
Thank you!
Ignacio (La Plata, Argentina)
来源:https://stackoverflow.com/questions/2607008/jquery-punctuation-for-spanish-%c3%b3-%c3%ad-etc-not-working-in-ie8