如何在上载完成时使用Plupload通过Ajax返回数据? [英] How do I return data via Ajax using Plupload on Upload Complete?
问题描述
最近几个小时,我一直在尝试获取某些东西……在完成队列后,从pluploader找回来的东西仍然无济于事.
I've been trying for the last few hours to get something... anything back from the pluploader upon completion of the queue to no avail.
这是我的JS代码:
var uploader = $('#pluploadDiv').pluploadBootstrap();
uploader.bind("UploadComplete", function(up, files) {
var obj = $.parseJSON(response.response);
alert(obj.result);
});
在upload.php脚本的最后一行,我有:
On the very last line of the upload.php script, I have:
die('{"jsonrpc" : "2.0", "result" : "'.$_REQUEST['unitID'].'", "id" : "id"}');
这对我来说很有意义...但是它无法正常工作,文件上传没有问题,但是警报甚至没有触发...没有任何响应.
This makes sense to me... but it's not working, the files upload without problems, but the alert doesn't even fire off... there is no response whatsoever.
有想法吗?
使用新代码作为解决方案进行编辑
我正在使用的JS(感谢jbl):
The JS that I'm using (thanks 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脚本保持不变,最后一行代码:
Upload.php script stayed the same, last line of code:
die('{"jsonrpc" : "2.0", "result" : "'.$_REQUEST['unitID'].'", "id" : "id"}');
因此,基本上,当我创建外壳行以在上传脚本中将图像与之关联时,我会通过绑定到plupload对象的FileUploaded事件将行ID传递回原始表单到一个隐藏的输入字段中.
So basically when I create the shell row to associate images to in the upload script, I pass the row ID back to the original form into a hidden input field via the FileUploaded event that is bound to the plupload object.
<input type="hidden" name="vehicle_id_value" id="vehicle_id_value" value="" />
像魅力一样工作!
推荐答案
在上传过程中,可能已经上传了几个文件.在UploadComplete
阶段,个人响应不再可用.
如果要显示有关特定文件上载的信息,则应绑定到FileUploaded
事件而不是UploadComplete
.
像这样的东西:
Several files could have been uploaded as part of the upload process. The individuals responses are not avalaible anymore when on UploadComplete
stage.
If you want to display info about a specific file upload, you should bind to the FileUploaded
event instead of UploadComplete
.
Something like :
uploader.bind('FileUploaded', function(upldr, file, object) {
var myData;
try {
myData = eval(object.response);
} catch(err) {
myData = eval('(' + object.response + ')');
}
alert(myData.result);
});
希望这会有所帮助
这篇关于如何在上载完成时使用Plupload通过Ajax返回数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!