How can I use the contents of a locally stored .txt file as part of my HTML code?

by Aaron Tackett   Last Updated August 14, 2019 18:26 PM

I'm trying to create a weather widget to show the current weather at 20 different locations on 20 different deployed Raspberry Pi's. Without a good way to detect the location of each of those RPi's, I have resorted to creating a .txt file that simply lists the city and state that I can send to each RPi. I will be sending the same HTML code for the weather widget to all RPi's, the only difference being the .txt file with the correct city and state. How would I go about reading the city and state from the .txt file and placing the contents in my html code?

I've tried using and tags, but not sure how to use them correctly. I have a file named "citystate.txt" with "Chicago, IL" (without quotes) as the only text in the doc.

<body>
<div>
    <!--HTML contents-->
</div>

<script>
    const city = {TRYING TO GET THE CONTENTS OF CITYSTATE.TXT TO BE USED FOR THIS VARIABLE};

</script>
</body>

Basically, the HTML file will be stored locally and run with the .txt file, so it's not HTML code running on a server trying to read the contents of a file on a client computer.

Tags : html


Related Questions


parsing/extracting a HTML Table, Website in Java

Updated July 11, 2015 20:11 PM



What do &lt; and &gt; stand for?

Updated October 31, 2017 15:26 PM