I want to display a file named Venues_location.html which is in the Templates directory.
I made a button clicking on which it needs display the html file in the div named Analytic area.
Its the name of the html file actually.
I came here from stack overflow where i was suggested to use this.
Apologies for replying late, had power outage here.
Sorry, I was being very explicit here about the code.
You’re doing a GET. You’re getting a response. In your code, you’re calling the function response.text and assigning it to a variable named response.
However, you’re not using that variable (response) to add the data to your HTML - you’re trying to use a variable named data, which isn’t defined anywhere in this function.
function load_home()
{
return fetch("{% url 'venues_location' %}") // or whatever url you assign to that view
.then(response => response.text())
.then(data => document.getElementsByClassName("Analytic_area").innerHTML=response);
}
getElementsByClassName returns an array, not a singular element. You either need to select which element from the array, or iterate over the full list.
It means it returns every tag that has that class name assigned to it. So even if you’re only assigning that class once, you’re still getting back an array. It’s just that that array only has one element.
Well this means the whole approach of mine is wrong. Since I named the div “Analytic_Area” where I wanted to display the html and I am using it in getElementsByClassName.
No, your basic approach is ok. (I wouldn’t have used the class attribute for this, but that’s a personal preference and not an indication that anything is technically “wrong”.)