0

I have to return a plain text got from a file from server and show in my webpage.

I am getting the file fine with ajax but I have problems with accents because it is in spanish and I have special characters like á, é, í...

Instead of that, I am getting squares with interrogation mark inside.

txt file has the correct symbol and I see it fine inside of it.

This is how I am getting and showing the file:

$.when(

   $.ajax({
                 type: "POST",
                 url: urlServer+"openDocument.php",
                 contentType: "application/text; charset=utf-8",
                 dataType: "text",
                 success: function(response) {
                     respuesta = response;
                 },

                 error: function(xhr, status, message) { alert("Status: " + status + "\nsaveDocument: " + message); }
                 })


                 ).then(function(){
                     //console.log(respuesta);
                    document.getElementById("divInfo").innerHTML = respuesta;
                 }
    );
Biribu
  • 3,615
  • 13
  • 43
  • 79

1 Answers1

0
dataType:

The type of data that you're expecting back from the server.

contentType:

When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding.

Your dataType is wrong. The default is: Intelligent Guess, other available types are (xml, json, script, or html). It should be html in your case. Read more here.

Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
  • Thanks but I am still getting the same problem. I changed to html and deleted contentType due to nothing is sent to the server. – Biribu Nov 21 '13 at 08:59