Is it possible to set the charset in an ajax request?

Asked

Viewed 25 times

0

I’m having a problem with the characters. I basically open txt(accent) files through ajax, but I’m having trouble with the accents. I was wondering if there is a way for ajax to open txt file with accents.

<script charset="UTF-8" >
    function corpo(titulo, texto) {
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("titulo").innerHTML = titulo;
            document.getElementById("corpo").innerHTML = this.responseText;
        }
      };
      xhttp.open("GET", 'arquivos/'+texto, true);
      xhttp.send();
    }
</script>

1 answer

-1

You must save the text file in utf-8 format. Open the file using the notepad, click on "save as..." and next to the "Save" change button to utf-8

Browser other questions tagged

You are not signed in. Login or sign up in order to post.