javascript treating special characters as utf characters

157 views Asked by At

My subject line might not be that great to explain my problem but a screenshot will.

enter image description here

The screenshot contains 2 screens. The right one is the JS editor where I have written the actual code to replace the special character to " ' ". On the left is the what I am seeing in the chrome browser.

Is it possible to replace the special characters through JS similar to the way I am trying?

My main problem is I am calling a ashx handler using ajax call through javascript. This handler is returning me the special characters. I have checked that I have the following code in my master page.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Have also tried the following but in vain

<meta http-equiv="Content-Type" content="text/plain; charset=utf-8" />

I am now in the process of updating my SQL Server 2008 fields as per the following posts but I am not very sure if this will solve the problem.

ASP.NET special character problem

Classic ASP gremlims, getting a  inserted into text whenever an HTML special character is used

Help which involves Javascript will be preferable, if possible.

Thanks in advance!

Cheers!

2

There are 2 answers

0
samar On BEST ANSWER

This is really surprising in stackoverflow for a question with just 9 views and no answers.

Anyways found a relevant post here which helped solve my problem.

So, wrote something to the following (like a regex) to get the issue resolved.

var modTitle = article.Title.replace(/[–]/gi, '-');

Cheers.

0
Dimitar Yankovski On

Here is very simple approach to remove all special characters. Suppose to work even with old deprecated versions of browsers. Hope helps.

var modTitle = article.Title.replace(/[^\w\s]/gi, '');

Best regards, Dimitar