gpt4 book ai didi

javascript - 使用 AJAX 为 plupload 回显值

转载 作者:行者123 更新时间:2023-11-30 17:36:49 26 4
gpt4 key购买 nike

您好,这是我用于 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);

但是当我将它添加到我的代码中时,它一直返回“您的浏览器不支持 HTML5、Flash、silverlight、html4”

如果我去掉 Fileuploaded 方法,它工作正常。

最佳答案

解决了。应该是这样的。

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

关于javascript - 使用 AJAX 为 plupload 回显值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21873208/

26 4 0