javascript - Spanish special characters like á ó while displaying shows jumbled or garbage value - Stack Overf

I have a Spanish validation message which I'm trying to display using my JavaScript.And all the s

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?

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?

Share Improve this question edited Mar 22, 2011 at 23:21 ChrisF 137k31 gold badges264 silver badges334 bronze badges asked Mar 22, 2011 at 22:44 alice7alice7 3,88014 gold badges67 silver badges95 bronze badges 2
  • What framework are you using that uses the <% %> notation? – Gabe Commented Mar 22, 2011 at 22:50
  • framework 4 and using ASP.NET MVC 2 – alice7 Commented Mar 22, 2011 at 22:52
Add a ment  | 

2 Answers 2

Reset to default 5

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.

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745043092a4607928.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信