I have a webservice that returns html string as response. I want to display the response in a div element. The response I am getting from service is
<span style="text-indent: 29px;padding-top:35px;font-size: 16pt;font-family: Arial;color: #FFFFFF;font-weight: bold;position: absolute;text-decoration: none;">89</span>
<span style="text-indent: 41px;padding-top: 58px;font-size: 8pt;letter-spacing: 1px;font-family: Arial;color: #E5DA95;font-weight: bold;position: absolute;text-decoration: none">89</span>
<span style="text-indent: 55px;padding-top: 58px;font-size: 8pt;letter-spacing: 1px;font-family: Arial;color: #E5DA95;font-weight: bold;position: absolute;text-decoration: none">-</span>
<span style="text-indent: 59px;padding-top: 58px;font-size: 8pt;letter-spacing: 1px;font-family: Arial;color: #E5DA95;font-weight: bold;position: absolute;text-decoration: none">92</span>
<img src="https://www.autocheck.com/members/img/freeLinkScore/scoreBanner4.gif" height="75" width="75" border="0">
I used the statement div.innerHTML = response;
The response is getting displayed as text instead of HTML. Can someone please tell me how to display the response as html inside the div.
If that’s your webservice, change its to output an un-HTML-encoded response.
Otherwise you will have to HTML decode the response before setting it as content.
I looked for a lightweight decoder and couldn’t find one that was more robust than simple regex.
So, this will probably work for your immediate needs, just beware that it can break on certain combinations of content (which seem unlikely in this case).
.
PS: Be sure that this webserver can’t supply you with malicious html, like
<script>tags.