4

When I receive html text by ajax in asp.net application it looks like:

<span%20style='color:green;font-weight:bold'>%20Text%20Msg</span>

how is it possible in javascript decode that text to normal html?

<span style='color:green;font-weight:bold'> Text Msg </span>

Thanks!

3
  • 3
    There is no technical reason it should look like that - especially since it looks like some strange mixture of HTML and URL encoding which neither does JSON require. You should check you server-side script and find out why it's being encoded and turn it off. Commented Jan 14, 2011 at 15:52
  • Are you using an XSLT to generate the markup? What is generating this code? Commented Jan 14, 2011 at 16:00
  • It looks like the string is double encoded: first Html Encoded and then URL encoded. Why is that so? Commented Jan 14, 2011 at 16:00

2 Answers 2

1

Nice function here that does it for you - http://phpjs.org/functions/htmlspecialchars_decode:427

Sign up to request clarification or add additional context in comments.

Comments

0

You are probably best suited with finding a server side solution as already mentioned in the comments, since this seems like a server side problem.

If you for some reason wish to do this client side anyway, here is a solution:

var str = "&lt;span%20style='color:green;font-weight:bold'&gt;%20Text%20Msg&lt;/span&gt;";
var fixedStr = decodeURIComponent(str).replace(/&lt;/g,'<').replace(/&gt;/g,'>');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.