I use an AJAX .get()
method to load HTML for a "Product Search" app and render it into a HTML node ($searchModalBody
):
productSearch: function productSearch(e, element) {
var $searchModal = $('#product-search-modal');
var $searchModalBody = $searchModal.find('.modal-body');
var url = $searchModal.data('url');
...
$.get(url, {
fromQuote: true, customerNumber: custNumber, hasQtyField: false
}).done(function (response) {
$searchModalBody.html(response);
})
How can I sanitize the response to avoid any DOM XSS?
I've read that .text()
is preferred over .html()
, but since I am loading HTML, .text()
will just escape all of it.
Sorry if I have missed anything. I've been trying to read up on XSS prevention, but couldn't find anything. I might just not fully understand what I need to be doing/looking for.