【发布时间】:2013-12-24 08:19:47
【问题描述】:
我正在构建一个照片上传表单,并决定使用 jQuery 插件jquery-file-upload,但遇到了一些问题......和问题。
首先,我正在使用的代码(与basic 版本一起使用):
// File upload function
jQuery(function() {
jQuery('#pick-photos').click(function(){
jQuery('#file-upload').click();
});
// Initialize the jQuery File Upload plugin
jQuery('#photo-upload').fileupload({
dataType: 'json',
add: function (e, data) {
jQuery.each(data.result.files, function (index, file) {
jQuery('<p/>').text(file.name).appendTo(document.body);
});
// Append the file name and file size
tpl.find('p').text(data.files[0].name)
.append('<i>' + formatFileSize(data.files[0].size) + '</i>');
jQuery('#upload').click(function() {
data.submit();
});
},
progressall: function(e, data) {
// Calculated the completion percentage of the upload
var progress = parseInt(data.loaded / data.total * 100, 10);
jQuery('#upload-progress .progress-bar').css(
'width',
progress + '%'
);
},
});
// Helper function that formats the file sizes
function formatFileSize(bytes) {
if (typeof bytes !== 'number') {
return '';
}
if (bytes >= 1000000000) {
return (bytes / 1000000000).toFixed(2) + ' GB';
}
if (bytes >= 1000000) {
return (bytes / 1000000).toFixed(2) + ' MB';
}
return (bytes / 1000).toFixed(2) + ' KB';
}
});
我面临的问题是这行代码jQuery('#photo-upload').fileupload({上的错误Uncaught TypeError: Object [object Object] has no method 'fileupload'
其次,我想知道如何在此代码中包含自定义 ajax...以便我可以根据成功或错误更改页面内容。
我们将接受任何帮助!
【问题讨论】:
标签: php jquery ajax file-upload jquery-file-upload