I have implemented the following code to asynchronously upload a file to the server:
HTML:
<form id="file_upload" action="UploadFile.ashx" target="upload-target" method="post" enctype="multipart/form-data" onsubmit="javascript:return uploadClicked();">
<input type="file" id="newFile" name="newFile" />
<input type="submit" />
<iframe id="upload-target" name="upload-target"></iframe>
</form>
Upon clicking the submit button, the uploadClicked() function will be executed:
function uploadClicked() {
if (condition == true)
return true; //the form will submit
else
return false;
}
The generic handler UploadFile.ashx will then save the file and provide the result:
if (context.Request.Files.Count > 0)
{
context.Request.Files["newFile"].SaveAs(HttpContext.Current.Server.MapPath("/Images/myFile.png"));
response.Write("DONE");
}
else
{
response.Write("FAILED");
}
This process works effectively displaying the result in the iframe tag.
Is there any way to receive the result ("DONE" or "FAILED") on the client-side like this ?
function uploadFinished()
{
if (response == "DONE")
{
//show the result
}
else
{
//show error
}
}
Kindly assist me with achieving this without utilizing JQuery.
Thank you in advance.