I am very new to HTML/javascript and I have seen a bunch of questions like this but I can’t seem to make head of tail of the solution provided. I have the following HTML code in the body section(including what is relevant):
<div>
<ul id="playerNames">
<li><b>Harden</b></li>
<li><b>Giannis</b></li>
<li><b>Lebron</b></li>
<li><b>Booker</b></li>
<li><b>Lavine</b></li>
<li><b>Westbrook</b></li>
<li><b>Jokic</b></li>
</ul>
</div>
There is some javascript below (also in the body of the same file):
<script type = "text/javascript">
$(document).ready(function(){
$( "playerNames" ).load( 'nba2019_names.php' );
});
</script>
And I have the following php code in a separate file that it meant to load a csv file that I am downloaded. All of these files are in the same folder.
$h=fopen('2019_nba_player_names.csv','r');
$data = fgetcsv($h, 1000, ",");
while(($data = fgetcsv($h, 1000, ",")) !== FALSE){
echo $row."n";
}
What I am trying to do is get the information in the csv to become an html list, and then replace the html code/list that is already in the ul. The names in the current ul are just placeholders. However, all that loads into the page is the placeholder names, and the code to get the csv has no effect. Can anybody help me out with this?
2
Answers
Try:
ajax code
php code
update: you can use this code to get data from
csv file
reference
Why have JS at all? I’ll assume for now that there is only a bunch of names in your .csv file.