我想使用blueimp文件上传插件来异步上传图片,但是当我尝试上传它们时,什么也没有发生。根本没有任何回调函数被触发。我正在使用此功能将文件上传器绑定到文件输入。blueimp jQuery文件上传未被触发
var initFileUpload = function (gender) {
//Used to bind fileupload plugin and send files
//bind file upload
$('#add_form').fileupload({
namespace: gender+'_image',
singleFileUploads: true,
formData: [{name:'gender', value: gender}],
fileInput: $("#"+gender+'_image'),
done: function(e, data){
alert('success '+data.result);
}
});
//Bind event callbacks
$('#add_form').bind('fileuploadsend', function (e, data) {
console.log('sent');
});
$('#add_form').bind('fileuploaddone', function (e, data) {
console.log('done');
});
$('#add_form').bind('fileuploadfail', function (e, data) {
console.log(data.result);
});
$('#add_form').bind('fileuploadalways', function (e, data) {
console.log(data.result);
});
}
这是由多文件上传教程here.启发我做这种方式,因为我有不同的名称,3个不同的输入。然后我在我的ajax调用中手动发送send函数,或者尝试。
$.ajax({
type: "POST",
url: "/manage/processadditem",
data: $("#add_form").serialize(),
dataType: "html",
success: function(response, textStatus, XHR)
{
if(response.indexOf('invalid') >= 0 || response.indexOf('Exception') >= 0){
//Show them their errors
alert(response);
}
else{
//Upload item images
//Send files
$('#add_form').fileupload('send', {fileInput: $("#neutral_image"), url: '/manage/items/itemimage/test' });
$('#add_form').fileupload('send', {fileInput: $("#male_image"), url: '/manage/items/itemimage/test' });
$('#add_form').fileupload('send', {fileInput: $("#female_image"), url: '/manage/items/itemimage/test' });
alert('should have uploaded image to cdn.completeset.com/items/test_nla.jpg if gender was neutral');
}
},
error: function(jqXHR, textStatus, errorThrown){
alert('An error occurred, please try again later.');
}
});
我下节的编程文件上传,您可以使用发送方法与像$('#fileupload').fileupload('send', {files: filesList});
行手动发送文件的文档here中发现,这样就是我试图用发送的文件。不幸的是,我没有得到任何回调函数的回应,我不知道为什么。
确保您没有包括jQuery.js两次。另外请记住,如果您使用的是jQuery工具,jQuery Tools有时会包含它自己的jQuery版本。 – 2012-08-09 18:19:36
@KevinB这摆脱了错误信息,但现在它只是默默地失败。你知道任何我可以从中获得调试信息的方法吗? – jaimerump 2012-08-09 18:36:19
尝试绑定到失败事件。 '('#add_form')。on('fileuploadfail',func);'或'.bind'如果使用旧的jQuery。 – 2012-08-09 18:40:44