I am trying to upload a file to my website and preview it without making the website refresh, but I cannot figure out how to do it, right now I select a file with the <input type=file> but I have a JQuery script that onchange submits the input with this code:
document.getElementById('file-upload').onchange = function () {
document.getElementById("upload-form").submit();
};
How can I make this without refreshing the page after the POST? My Form looks like this (It is an ASP.NET Core 6 project):
<form id="upload-form" asp-action="UploadFile" asp-controller="Home" enctype="multipart/form-data">
<label for="file-upload" class="custom-file-upload">
<i class="fa fa-cloud-upload"></i> Ladda upp
</label>
<input id="file-upload" type="file" name="stlFile" />
</form>