我正在研究jquery plupload插件。这个插件有很多事件,我使用了其中一些并且工作正常。此时我需要使用Error
事件并在此事件中访问ajax响应。我怎样才能做到这一点?这是我的上传器小部件:
$("#uploader").plupload({
init: {
BeforeUpload: function(up, file) {
//some functions
},
FileUploaded: function(up, file, object) {
// some functions
},
UploadComplete: function(up) {
},
QueueChanged: function() {
//some functions
},
Error: function(/* what is the parameter? */){
//How can i access ajax response here?
}
},
// General settings
runtimes: 'html5',
url: pageVars.contextPath + "/file/uploadDo",
// Maximum file size
max_file_size: '20000mb',
chunk_size: '10mb',
// Specify what files to browse for
filters: [
{title: "Image files", extensions: "jpg,gif,png"},
{title: "Zip files", extensions: "zip,rar,iso"},
{title: "PDF files", extensions: "pdf"},
{title: "EXE files", extensions: "exe"},
{title: "Music", extensions: "mp3"},
],
// Rename files by clicking on their titles
rename: true,
// Sort files
sortable: true,
// Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
dragdrop: true,
// Views to activate
views: {
list: false,
thumbs: true, // Show thumbs
active: 'thumbs'
},
});
答案 0 :(得分:0)
与plupload演示一样,您可以处理错误事件:
上传页面(js script,examples / custom.html):
Error: function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
}
PHP (服务器端上传处理程序,examples / upload.php):
if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
}