Recently helped a friend to do a project encountered Type=file change event can only be performed once the problem, degree Niang a bit, found to provide a variety of solutions, so decided to record my thinking direction and the final solution.
At first to help a friend to do a project, the project encountered uploading files, did not think too much, the code knocked Up, the upload done, excitedly, a test, EI, how to do, how can not upload, the programmer of all kinds of grasping nasty ah, the beginning of the Niang find solutions, find to find, calm down, and think of solutions;
Egg <input type= ' file '/> design, regardless of file upload success or not, has been added to the file has been recorded, so will not perform the change event, probably the reason to know, do it, if I can clear the record, the event will not be able to trigger it, try a bit, It's not successful. Continue to find the method, if I replace the <input type= ' file '/> tag, and then rebind the change event what would be, try it out, succeed, and paste the following code:
<form action= "/api/index/browse" enctype= "Multipart/form-data" id= "Form_upload" method= "POST" >
<input id= "fileUpload" type= "file" name= "file" style= "Display:none" >
</form>
$ (' input[id=fileupload] '). Click ();
var count = 0;
$ (' input[id=fileupload] '). Unbind (). Change (function () {
$ (' #form_Upload '). Ajaxsubmit (options);
});
var options = {
Success:function (data) {
$scope. OrderInfo = eval (data);
$scope. $apply (function () {
$scope. OrderInfo = eval (data);
Start to avoid the change of the Type=file control () can only be performed once, replace the control, rebind the event
count++;
$ ("#fileUpload"). ReplaceWith (' <input type= "file" id= "FileUpload" name= "file" style= "Display:none;" title= "' + Count + '/> ');
$ (' #fileUpload '). On (' Change ', function () {
$ (' #form_Upload '). Ajaxsubmit (options);
});
End
$http. Post (URL, params). Success (function (data) {
Do something
}, function () {
Do something
});
});
}
};