在过去的几个小时里,我一直在尝试获取一些东西......在完成队列后从pluploader返回的任何内容都无济于事。
这是我的JS代码:
var uploader = $('#pluploadDiv').pluploadBootstrap();
uploader.bind("UploadComplete", function(up, files) {
var obj = $.parseJSON(response.response);
alert(obj.result);
});
在upload.php脚本的最后一行,我有:
die('{"jsonrpc" : "2.0", "result" : "'.$_REQUEST['unitID'].'", "id" : "id"}');
这对我来说很有意义......但它不起作用,文件上传没有问题,但警报甚至没有触发......没有任何回应。
思想?
使用新代码作为解决方案进行编辑
我正在使用的JS(感谢jbl):
var uploader = $('#pluploadDiv').pluploadBootstrap();
uploader.bind('FileUploaded', function(upldr, file, object) {
var myData;
try {
myData = eval(object.response);
} catch(err) {
myData = eval('(' + object.response + ')');
}
$("#vehicle_id_value").val(myData.result);
});
Upload.php脚本保持不变,最后一行代码:
die('{"jsonrpc" : "2.0", "result" : "'.$_REQUEST['unitID'].'", "id" : "id"}');
所以基本上当我创建shell行以将图像关联到上传脚本时,我通过绑定到plupload对象的FileUploaded事件将行ID传回原始表单到一个隐藏的输入字段。
<input type="hidden" name="vehicle_id_value" id="vehicle_id_value" value="" />
像魅力一样!
答案 0 :(得分:10)
可以在上传过程中上传多个文件。在UploadComplete
阶段,个人反应不再可用。
如果要显示有关特定文件上载的信息,则应绑定到FileUploaded
事件而不是UploadComplete
。
类似的东西:
uploader.bind('FileUploaded', function(upldr, file, object) {
var myData;
try {
myData = eval(object.response);
} catch(err) {
myData = eval('(' + object.response + ')');
}
alert(myData.result);
});
希望这会有所帮助
答案 1 :(得分:1)
function fileupload(fileuploadid, urlashx, foldername, keyid, filelimit, filefilters) {
$("#" + fileuploadid).plupload({
// General settings
runtimes: 'html5,flash,silverlight,html4',
url: urlashx,
//Set parameter for server side
multipart_params: {
foldername: foldername,
keyid: keyid
},
// Maximum file size
max_file_size: filelimit,
// User can upload no more then 20 files in one go (sets multiple_queues to false)
max_file_count: 20,
multiple_queues: true,
//chunk_size: '10mb',
// Resize images on clientside if we can
resize: {
//width: 200,
//height: 200,
quality: 90,
crop: false // crop to exact dimensions
},
// Specify what files to browse for
filters: [
{ title: "Allowed files", extensions: filefilters }
],
// 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: true,
thumbs: true, // Show thumbs
active: 'thumbs'
},
// Flash settings
flash_swf_url: 'plupload/js/Moxie.swf',
// Silverlight settings
silverlight_xap_url: 'plupload/js/Moxie.xap',
// Post init events, bound after the internal events
init: {
FileUploaded: function (up, file, jsonMsg) {
var json = JSON.parse(jsonMsg.response); // now I have json object
if (json.success) {
AlertMessage("Message", json.message, "success", "False");
} else {
AlertMessage("Message", json.message, "error", "False");
}
up.splice(); //remove items of container
up.refresh(); //refresh container
}
}
});
}
答案 2 :(得分:0)
echo '{"jsonrpc" : "2.0", "result" : "'.$_REQUEST['unitID'].'", "id" : "id"}';
答案 3 :(得分:0)
uploader.bind('FileUploaded', function (up, file, res) {
var res1 = res.response.replace('"{', '{').replace('}"', '}');
var objResponse = JSON.parse(res1);
alert(objResponse.fn);
});