I have an empty modal on my page and I'm performing an ajax call as below (simplified for reading)
function returnIt(x)
{
$.ajax({
type:"POST",
url:"link",
data:{id:"123"},
success: function(data)
{
data=JSON.parse(data);
var content=document.getElementById("returnItModalBody").innerHTML;
for(var i=0;i<data.length;i++)
{
if(data[i]["nick"]==1)
content+="<p>"+data[i]["upd"]+"</p>";
else
content+="<p>"+data[i]["upd"]+"</p>";
}
alert(content);
$("#returnItModal").modal('show');
}
});
}
When I tell the script to alert with content
it shows it should show in modal. When modal opens, there is nothing in its body.
What am I missing here?
Thanks
var content=document.getElementById("returnItModalBody").innerHTML;
That copies the value of innerHTML
(a string) to content
.
content+="<p>"+data[i]["upd"]+"</p>";
Then you assign a new string to content
alert(content)
Then you look at the string in content
You never change innerHTML
.
If you want to change innerHTML
then you have to assign a new value to it.