嗨这是我的plupload的JS文件
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
browse_button : 'pickfiles', // you can pass in id...
container: document.getElementById('container'), // ... or DOM Element itself
url : '../../assets/php/upload.php',
flash_swf_url : '../js/Moxie.swf',
silverlight_xap_url : '../js/Moxie.xap',
filters : {
max_file_size : '10mb',
mime_types: [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Video files", extensions : "mp4"}
]
},
init: {
PostInit: function() {
document.getElementById('filelist').innerHTML = '';
document.getElementById('uploadfiles').onclick = function() {
uploader.start();
return false;
};
},
FilesAdded: function(up, files) {
plupload.each(files, function(file) {
document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
});
},
UploadProgress: function(up, file) {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
},
Error: function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
}
}
});
uploader.init();
在我的upload.php中,我返回一个
echo $name
我希望我的plupload在上传完成时显示$ name。
我试过这个解决方案 How do I return data via Ajax using Plupload on Upload Complete?
uploader.bind('FileUploaded', function(upldr, file, object) {
var myData;
try {
myData = eval(object.response);
} catch(err) {
myData = eval('(' + object.response + ')');
}
alert(myData.result);
但是当我将它添加到我的代码中时,它会一直返回&#34;您的浏览不支持HTML5,Flash,silverlight,html4&#34;
如果我取出Fileuploaded方法,它可以正常工作。
答案 0 :(得分:2)
解决了这个问题。应该是这样的。
UploadProgress: function(up, file) {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
},
FileUploaded: function(up, file, info) {
// Called when a file has finished uploading
document.getElementById('console').innerHTML += "#" + info.response + ": ";
var myData;
try {
myData = eval(info.response);
} catch(err) {
myData = eval('(' + info.response + ')');
}
$("#video_id").val(info.result);
},
Error: function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
}