0

I'm calling a Web Service method to get some html data. When I set the returned data as innerHtml for a div tag then it is displayed as-is (literal text). I don't want my returned html data to be encoded. How to do this?

Here is my JQuery code:

$(document).ready(function () {
            $("#btnGetLaboratories").click(function () {
                var oService = new LaboratoryService();
                var fResult = oService.send(); // returns some html data

                $("#divResult").html(fResult);
            });
        });

Here is my html code:

<input id="btnGetLaboratories" type="button" value="Get Laboratories" />
    <div id="divResult">

    </div>
3
  • Just to clarify, you're seeing the literal HTML tags of fResult on the rendered page? Could you show an example of data it returns and how it looks on the page? It's not very clear what the problem is. Commented Jun 21, 2014 at 10:43
  • For example, if the return data is <b>hello</b>, then my div (i.e., divResult) innerHtml becomes <b>hello</b>; This is not what I'm expecting. I expect that a hello to be rendered on page. Commented Jun 21, 2014 at 10:50
  • @user3747698 have you checked with my answer Commented Jun 21, 2014 at 10:55

1 Answer 1

1

Try using

$(document).ready(function () {
        $("#btnGetLaboratories").click(function () {
            var oService = new LaboratoryService();
            var fResult = oService.send(); // returns some html data

            var newData = $('<div/>').html(fResult).text();

            $("#divResult").html(newData);
        });
    });

Hope it will help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.