Problems displaying javascript string

2

I have the following code:

$(function(){
    var curso = controller.getNomeCurso();
    $("#curso").text(curso);
});

The problem is in the line 18 because I can not display values with special characters correctly.

Example: When sending Nutrição , the displayed value is Nutri%C3%A7%C3%A3o , even in line 4 there is a meta tag defining charset as UTF-8 .

How can I resolve this?

    
asked by anonymous 01.06.2015 / 22:17

3 answers

1

Dude I modified the controller function with the @MarcusVinicius hint.

var controller = {
    getNomeCurso : function() {
        return window.decodeURIComponent(itens[0]); <-- window.decodeURIComponent("variavel para codificar")

    },
    voltar: function(){
        location.href = "turmas.html";
    }
};
    
02.06.2015 / 14:50
1

try this:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
01.06.2015 / 22:24
1

The string appears to be encoded. If you use the encodeURIComponent function in the string "Nutrition" you will get "Nutrition" .

Then, to fix, use:

var curso = window.decodeURIComponent(controller.getNomeCurso());
$("#curso").text(curso);

var curso = window.decodeURIComponent("Nutri%C3%A7%C3%A3o");
$("#curso").text(curso);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="curso"></div>
    
01.06.2015 / 22:25