I have a jQuery datatable and I'm trying to use a popover to show some comments, but comments containing a single quote is preventing the popover from showing the whole comment.
Within the datatable cell, the entire comment is being shown. Not sure why the popover is failing to show the whole comment.
Here is the code for the datatable (simplified as much as possible):
$.ajax({
url: 'process/getTargetSheet.php',
type: 'POST',
data: '',
dataType: 'html',
success: function(data, textStatus, jqXHR){
var jsonObject = JSON.parse(data);
var table = $('#example1').DataTable({
"dom": "Rlfrtip",
"data": jsonObject,
"columns": [
{
"data": "tsc_tgcomment",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol)
{
var tccomment = oData.tsc_tgcomment;
$(nTd).html("<a tabindex='0' class='tcDisplay'
data-toggle='popover' data-trigger='focus'
data-content='"+tccomment+"' id='tcDisplay'
data-toggle='modal'>"+tccomment.substring(0, 50)+"...</span>");
$(function () {
$('[data-toggle="popover"]').popover();
});
},
// some more columns
}
]
});
},
error: // nothing important here
});
So in the $(nTd) portion above, you'll see where I added the tccomment into the popover. But strings that have quotes fail to show the whole comment.
I tried to use "escape" in this manner:
data-content='"+escape(tccomment)+"'
But the comment prints out beyond the popover and includes a bunch of percent signs.
How can I fix this to show the whole comment in the popover?