Spanish special characters like á ó while displayi

2019-05-28 12:31发布

I have a Spanish validation message which I'm trying to display using my JavaScript. And all the special characters like above gets changed into & #243;. And it is only happening when I'm using JavaScript, there are couple of more validation messages in Spanish which I'm displaying through server side and they are fine.

errorString = "<%:Validation.xyz %>";

I'm trying to get from resource file.

Can some one think of quick work around?

2条回答
聊天终结者
2楼-- · 2019-05-28 13:04

What you call garbage is actually but the HTML encoded value of the corresponding character and is there to prevent you from XSS. The encoding happens because you are using <%: which automatically HTML encodes the string but this shouldn't be a problem for your javascript. Example:

var text = 'hello &#243';
document.getElementById('foo').innerHTML = text;

works just fine and displays hello ó in the corresponding DOM element.

查看更多
混吃等死
3楼-- · 2019-05-28 13:14

Check if you saved your file with UTF-8 encoding (just in case). It happens that it goes into TFS without UTF8 BOM and then mess can happen on client side.

查看更多
登录 后发表回答