javascript - Page uploads file twice? -
I am trying to include the upload progress bar on my page.
I have been successful in getting the progress bar using this method:
When the user is clicking on the upload file, the progress bar does business and shows how much is uploaded and when it is completed.
However, when the user submits the form again, the file is being uploaded again (the Chrome file shows upload information at the bottom of the screen).
How can I avoid him? Also, how can I get it, so do not upload file button?
All I want is the submit button, the progress bar is showing progress and then the upload is going on to a different page (some via PHP which needs to be posted with the information )?
My relevant code is below ...
& lt; Form method = "post" action = "../../ property / php / actiontest.php" name = 'main form' encrypt = "multipart / form-data" onsmitt = "reverse checkform ()" & gt; & Lt; Input type = "text" name = "customer" placeholder = "customer" required /> & Lt; Br / & gt; & Lt; Input type = "file" name = "file1" id = "file1" & gt; & Lt; Br / & gt; & Lt; Input type = "button" value = "upload file" onclick = "uploadFile ()" /> & Lt; Progress ID = "progress big" value = "0" max = "100" style = "width: 100%;" & Gt; & Lt; / Progress & gt; & Lt; Input type = "submit" id = "submit" /> & Lt; / Form & gt; & Lt; Script type = "text / javascript" & gt; Function _ (l) {return document. GetElementById (L); } Function upload file () {var file = _ ("file1"). Files [0]; Var formidata = new form data (); Formdata.append ("file1", file); Var Ajax = New XMLHttpRequest (); Ajax.upload.addEventListener ("progress", progress handler, wrong); Ajax.addEventListener ("load", full handler, incorrect); //ajax.open("POST "," file_upload_parser.php "); Ajax.open ("Post", "../../assets/php/actiontest.php"); Ajax.send (formdata); } Function Progress Handler (Events) {var percentage = (event.loaded / event.total) * 100; _ ("Progress Big"). Value = mathematics (percent); } Function Full Handler (Event) {_ ("Progress Bar"). Value = 0; } & Lt; / Script & gt;
Since you have the file input field, when the form is submitted, go it Assuming in the form and uploading it. Resetting file fields with many browser support is a pain.
You can try doing something like this:
- After the file upload is complete, remove the element from the DOM and show a link to reset
- If the user wants to upload another file, then he clicks on this link and then resumes a file input field.
Comments
Post a Comment