Unescape HTML entities in Javascript?

前端 未结 30 2973
野趣味
野趣味 2020-11-21 05:40

I have some Javascript code that communicates with an XML-RPC backend. The XML-RPC returns strings of the form:


30条回答
  •  醉酒成梦
    2020-11-21 05:46

    I tried everything to remove & from a JSON array. None of the above examples, but https://stackoverflow.com/users/2030321/chris gave a great solution that led me to fix my problem.

    var stringtodecode="Hello world
    "; document.getElementById("decodeIt").innerHTML=stringtodecode; stringtodecode=document.getElementById("decodeIt").innerText

    I did not use, because I did not understand how to insert it into a modal window that was pulling JSON data into an array, but I did try this based upon the example, and it worked:

    var modal = document.getElementById('demodal');
    $('#ampersandcontent').text(replaceAll(data[0],"&", "&"));
    

    I like it because it was simple, and it works, but not sure why it's not widely used. Searched hi & low to find a simple solution. I continue to seek understanding of the syntax, and if there is any risk to using this. Have not found anything yet.

提交回复
热议问题