Stackoverflow Com Questions 13794204 Successful File Upload
Stackoverflow Com Questions 13794204 Successful File Upload
following code is working but with 2 issues: It is part of bigger form on the web page it appears
on.
0
<FORM id="my_file_upld_form"
style="display: inline;"
METHOD="POST"
ACTION="/cgi-bin/fileupload_ajax.pl"
ENCTYPE="multipart/form-data">
<INPUT TYPE="file" class="ajaxfileupload" NAME="myfile" SIZE="42">
<input type="hidden" class="ajaxfileupload" name="fileupload" value="ajax_fil
<input class="ajaxfileupload" type="submit" value="Upload"/>
</FORM>
1. it is allowing "blank" or empty (no file selection and upload button clicked) to upload. which
is causing 500 error on server.
2. bigger problem is: after the file is uploaded, a new blank page is opened in browser and
user has to use back button to go back to the page from where this was run. This happens
irrespective of the fact that the ajax script returns anything back or not.
how to fix? I am open to replace this piece of code on the page, if needed.
Share Improve this question Follow edited Dec 10, 2012 at 4:12 asked Dec 10, 2012 at 2:30
Rajeev
1,371 7 29 48
Add a comment
It's hard to tell exactly what is going wrong without your java script code. However I think I
know how to fix some of your problems.
0
1. Don't trust the client you need to handle in your backend code the ability to handle a form
that gives you bad data. You can validate the form client side but you always need to
validate server side as well.
Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF
2. I suspect this problem is happening because you aren't preventing the default event in
javascript. In jquery you would do
$("#my_file_upld_form").submit(function(e){
e.preventDefault()
})
Share Improve this answer Follow answered Dec 10, 2012 at 4:33
powerc9000
2,103 20 31
Add a comment
Not the answer you're looking for? Browse other questions tagged html ajax file-upload or
ask your own question.
Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF