6

在过去的几个小时里,我一直在尝试获取一些东西……在队列完成后从 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="" />

奇迹般有效!

4

4 回答 4

11

作为上传过程的一部分,可能已经上传了几个文件。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);
});

希望这会有所帮助

于 2013-05-15T07:18:10.517 回答
1

你试过回声而不是死吗?

echo '{"jsonrpc" : "2.0", "result" : "'.$_REQUEST['unitID'].'", "id" : "id"}';
于 2013-05-15T02:59:35.843 回答
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
            }
        }
    });
}

于 2019-07-27T04:29:25.837 回答
0
uploader.bind('FileUploaded', function (up, file, res) {
  var res1 = res.response.replace('"{', '{').replace('}"', '}');
  var objResponse = JSON.parse(res1);
  alert(objResponse.fn);
});
于 2016-08-27T05:07:28.857 回答