我正在使用 jquery 和 ASP,并且有一个 SQL 数据库,我使用函数 $.getJSON() 从中获取一些西类牙语的描述,其中包含“acentos”和“tildes”(á、é、í、ó、 ú、ñ 等)。
Chrome 4 和 FireFox 运行良好。问题出在 IE8 上:对于某些特定的查询,它挂起而没有返回结果。如果我使用 IE 将所有“ó”替换为“o”,则相同的结果集可以完美工作,因此我知道问题出在“acentos”(ó)。
我使用以下代码设置 ajax 调用:
$.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');
}
}
});
然后,调用 getJSON() 来获取带有“acentos”的描述,如下所示:
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');
}
任何提示将不胜感激。我已经用谷歌搜索了好几天,但没有找到这个问题的答案......:P
提前致谢, 伊格纳西奥(阿根廷拉普拉塔)
最佳答案
答案很简单,但我花了几天时间才发现。分享给有同样问题的大家。
解决方案是在响应对象 (ASP) 中或使用 PHP 中的 header 函数指定内容类型:
ASP
Response.ContentType="text/html; charset=iso-8859-1"
PHP
header("text/html; charset=iso-8859-1");
这必须是生成 JSON 对象的文件上响应的第一行(我认为)。如有任何意见,我们将不胜感激。
谢谢!
伊格纳西奥(阿根廷拉普拉塔)
关于JQuery 西类牙语标点符号(ó、í 等)在 IE8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2607008/