没有文件的jQuery-File-Upload [英] jQuery-File-Upload without file

查看:107
本文介绍了没有文件的jQuery-File-Upload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery插件"jQuery-File-Upload"来管理我拥有的表单.我尝试在Google上搜索我的问题,但到目前为止没有任何结果.

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.

现在,我知道这是一个专门用于上传文件的插件,但是,如果我们不得不重复代码以提供不带文件的提交的另一种AJAX调用,那么它将变得非常不便.

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?

谢谢 彼得

更新以添加代码:

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); } } );

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); } } );

推荐答案

我收到作者的回应,说该选项未在框架上实现:

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.

我决定使用其他jQuery插件 http://malsup.com/jquery/form/并不会迫使我重复使用或不使用文件附加方法提交表单的代码. 在IE9中可用.

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.

这篇关于没有文件的jQuery-File-Upload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆