I have received the following string from my ajax request:
As per json doc, "quotes must be escaped "
This is stored in data.description
and is embedded in the template as:
'<a href="#"' + 'data-title="' + data.description + '"></a>'
data-title
's value is used as a caption for lightbox plugin pop up. I tried the following function:
var HtmlEncode = function(s) {
var el = document.createElement("div");
el.innerText = el.textContent = s;
s = el.innerHTML;
return s;
}
as:
'<a href="#"' + 'data-title="' + HtmlEncode(data.description) + '"></a>'
Now since the data.description
contains multiple quotes javascript assumes them as multiple argument and throws error. I searched many other Stackoverflow posts which suggest to append the data in a div and retrieve its inner HTML but that is possible in my case.
Thanks