JQuery punctuation for Spanish (ó, í, etc.) does not work in IE8

I'm working with jquery and ASP and has a SQL database from which I get using the $ .getJSON () function some descriptions in spanish with "acentos" and "tildes" (á, é, í, ó, ú, ñ etc.).

In Chrome 4 and FireFox it works fine. Problem in IE8: With some specific request, it hangs without returning a result. If I replace all "-" with "o" using IE, the same result set works great, so I know the problem is with "acentos" (-).

I am setting up 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 getJSON () call to get the descriptions using "acentos" looks 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 would be appreciated. I searched the web many times without getting to the answer to this question ...: P

Thanks in advance, Ignacio (La Plata, Argentina)

+2


source to share


1 answer


The answer was very simple, but it took me a few days to discover. I am sharing it here, for anyone else who has the same problem.

The solution is to specify the content type directly in the response object (ASP) or using the header function in PHP:

ASP

Response.ContentType="text/html; charset=iso-8859-1"

      

PHP



header("text/html; charset=iso-8859-1");

      

This should be the first line of the response (I think), in the file that generates JSON objects. Any comments would be appreciated.

Thank!

Ignacio (La Plata, Argentina)

+3


source







All Articles