JQuery punctuation for spanish (ó, í, etc.) not working in IE8

浪子不回头ぞ 提交于 2019-12-13 16:21:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!