Javascript html decoding

When I get the ajax html text in an asp.net application, it looks like this:

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

how is it possible in javascript to decode this text in plain html?

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

Thanks!

+4
source share
2 answers

A nice feature here that does this for you is http://phpjs.org/functions/htmlspecialchars_decode:427

+1
source

Most likely, you are best off finding a server-side solution, as mentioned in the comments, as this seems like a server issue.

If for some reason you want to make this client side, here is the 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,'>'); 
0
source

All Articles