开发者

Javascript html decoding

开发者 https://www.devze.com 2023-02-04 01:35 出处:网络
When I receive html text by ajax in asp.net application it looks like: &a开发者_StackOverflowmp;lt;span%20style=\'color:green;font-weight:bold\'>%20Text%20Msg</span>

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

&a开发者_StackOverflowmp;lt;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!


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


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,'>');
0

精彩评论

暂无评论...
验证码 换一张
取 消