jQuery-File-Upload without file

♀尐吖头ヾ 提交于 2021-02-11 16:54:26

问题


I'm using the jQuery plugin "jQuery-File-Upload" to manage a form I have. I've tried searching for my problem on google but nothing so far.

The problem is that this form allows an optional field for file upload. When I insert a file it all goes ok, but when I decide to not include a file the plugin script won't even run.

Now I know this is a plugin specifically to upload files, nevertheless it becomes rather inconvenient if we have to duplicate code just to provide an alternative AJAX call for submissions without files.

Is there a way to solve this issue?

Thanks Peter

update to add code:

form.fileupload ( { url : 'php/file.php', dataType : 'json', autoUpload : false, replaceFileInput : false, sequentialUploads : false, maxFileSize : 10000000, minFileSize : 0, acceptFileTypes : /(\.|\/)(gif|jpe?g|png)$/i, add : function (e, data) { data.context = button.click ( function (e) { e.preventDefault (); // PARSE DATA FOR VALIDATION // OK TO SEND data.submit(); } ); }, fail : function (e, data) { console.log ('fail'); console.log (data); }, progressall : function (e, data) { console.log ('progress'); console.log (progress); }, done : function (e, data) { console.log ('done'); console.log (data); } } );


回答1:


I had the response from the author saying this option is not implemented on the framework: https://github.com/blueimp/jQuery-File-Upload/issues/3105.

I decided to go with a different jQuery plugin http://malsup.com/jquery/form/ that doesn't force me to duplicate code for a form submission with or without file attached methods. Works in IE9.



来源:https://stackoverflow.com/questions/23215608/jquery-file-upload-without-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!