I've seen a few questions relating to this, but almost all of them use php
. I have just a simple html file, with an input and a button. I've tried using proposed solutions, but I always get the error after I submit the form with the button. I have included the character enconding as utf-8
. I also have the <meta charset="utf-8" />
but commented out upon seeing other solutions on SO, which I have implemented to no avail.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<script src="index.js"></script>
<title>My Page</title>
</head>
<body>
<form name="data-form" enctype="multipart/form-data" method="post">
<input type="file" id="file-input">
<button id="form-btn" type="submit">Load File</button>
</form>
</body>
</html>
Based on my rudimentary understanding, this should read the file no problem. I'm trying to upload a JSON file, not sure if that's the issue. It is a valid JSON, I have checked and double-checked.
The index.js
file that is linked, currently does not interact with the file upload in anyway, so in the interest of brevity I have not included it.
EDIT
I "solved" this, I guess. More like bypassed it. I wrote a JS function (readFile()
) to read on click, and changed the button's type to type="button"
and put an onclick="readFile()"
and now it reads the file and eecutes properly. Hopefully maybe this will help someone else who has a similar problem. I guess this can be closed.