0

I am getting dynamic data from the database and appending to my html using html() function. Everything works fine but when the dynamic data contains '>' or '<' tag as data the script takes it as a html tag and the data and script breaks.

function showKeywordActivity(e, t, n, r, i) {
    var s = $(e).find("input.keywordFrequencyIdList").val();
    var o = $(e).find("input.keywordId").val();
    var u = $(e).find(".keywordValue").val();
    $(".hashKeyword").text("#" + u);
    $("#tabs-1").html('<div class="innerBox"><div class="innerBoxcontent scroll"><div class="loadingWrap"><div class="loading"></div></div></div><div class="dashboardBottombox"></div></div>');
    $.ajax({type: "POST",url: "url",data: {pageUrlHandle: n,keywordId: o,pattern: u,serviceType: t,startDate: r,endDate: i,keywordType: $("#keywordActivityTypeFilter").val(),keywordType: $("#activityFilter").val()},dataType: "html",async: true,success: function(t) {
            $(e).css("background", "#F8FAFF");
            $("#tabs-1").html(t);
            $(".scroll").each(function() {
                $(this).mCustomScrollbar({theme: "light",advanced: {updateOnBrowserResize: true,updateOnContentResize: true,autoExpandHorizontalScroll: false,autoScrollOnFocus: true}})
            })
        },error: function(e, t) {
        }})
}

How to solve this error. anyone please help me

2 Answers 2

2

Use $("#tabs-1").text(t); instead of .html(); to escape special characters.

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

Comments

0

If you want to html content to be placed inside some tag(lets say #target), then

 $('#target').html(content);

If you want to place text content, then

  $('#target').text(content);

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.