Вопрос

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

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top