Spanish special characters like á ó while displaying shows jumbled or garbage value

梦想与她 提交于 2019-12-08 03:08:15

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5398773/spanish-special-characters-like-%c3%a1-%c3%b3-while-displaying-shows-jumbled-or-garbage-va

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!