I have a problem to insert html into document using javascript.
Code that trying to insert html into document:
function loadTaskPage(taskId){
fetch("https://localhost:44321/api/Tasks/1")
.then(function(response){
return response.text();
}).then(function(data){
document.body.insertAdjacentHTML('beforeend', data);
}).catch(function(error){
alert(error);
})
}
This code part I took from tutorial, source code of tutorial could be found in this link: https://github.com/bstavroulakis/progressive-web-apps/blob/master/car-deals/js/carService.js
If I will try to open this link https://localhost:44321/api/Tasks/1 in browser I receive normally styled web page, but when I try to insert it to document, html code got escaped and don't display anything.
Inserted html looks like:
<div id="\"myModal\"" class="\"modal" fade\"="">...
The code below is bootstrap modal copied from code examples. As you see there appeared symbols \" that escapes quotes.
Response with html I receive from my ASP.Net Web Api with header: text/html
How should I insert this html code into document using javascript?
document.getElementById('main-content').innerHTML += data;like this. But still there appears only text without any styles and still as I said in a ticket all class attributes are escaped.", your html string should be"<div id=\"myModal\" class=\"modal" fade\">..."otherwise the string insideidis'"id"'see this fiddleid..." I meant that as an example, it's happening in more places than just theid<div id=\"myModal\" class=\"modal fade\">like this.