Hi, i am trying to load data through Ajax, it console logs perfectly but does not appear in my webpage, can anyone help please
My Views File:
def post_data(request):
qs = Post.objects.all()
data = []
for obj in qs:
item = {
'title': obj.title,
}
data.append(item)
return JsonResponse({"data": data})
My JavaScript File:
const pb = document.getElementById("post-box")
async function Start1() {
const a = await fetch("data/")
const data = await a.json()
console.log(data)
renderHTML(data)
}
Start1()
function renderHTML (OurData) {
var htmlstring =""
for (i=0; i < OurData.length; i++){
htmlstring += `<p> ${OurData[i]} </p>`
}
pb.insertAdjacentHTML("beforeend",htmlstring)
It console logs perfectly: here is the pic