0

I'm receiving from my server a string with " char as ". I would like to display this string correctly without any coded characters

So I try to use decodeURI or unescape function as follows:

decodeURI(""")
unescape(""")

buy still the output stays coded

"""

Any clue why?

Thanks!

georg
  • 211,518
  • 52
  • 313
  • 390
Shai Ben
  • 11
  • 2
  • If you're able to use jquey, [this SO question](http://stackoverflow.com/questions/5796718/html-entity-decode) have already been answered. – fuyushimoya Jun 25 '15 at 08:41
  • Im locking for a javascript solution since i want to store this values in variable. I using angularJs so i would like the code to look like this: var dataFromServer = ""; $scope.dataToDisplay = decodingFunction(dataFromServer); The question is what could be the decodingFunction? – Shai Ben Jun 25 '15 at 10:42

4 Answers4

0

decodeURI() and unescape() are used to decode URI content, not HTML. I think you are mixing your technologies.

If jquery is available then these might help you: Javascript decoding html entities How to decode HTML entities using jQuery?

Community
  • 1
  • 1
Chris Walsh
  • 3,423
  • 2
  • 42
  • 62
0

use Jquery

$("myel").html(""");

will result as proper string on the screen, while the source is "\

0

If you want the javascript-only version to decode that, use this:

function decodingFunctionVer(str) {
    var tmp = document.createElement("div");
    tmp.innerHTML = str;
    return tmp.textContent;
}

With jsFiddle demo.

fuyushimoya
  • 9,715
  • 3
  • 27
  • 34
0

Solved:

function decodeText(encodedText){
        var div = document.createElement('div');
        div.innerHTML = encodedText;
        var decoded = div.firstChild.nodeValue;
        return decoded;
    }

I don't like this solution becuse it includes creating a redundent element but it works.

Thanks for the help

Shai Ben
  • 11
  • 2