How do I return data via Ajax using Plupload on Upload Complete?

余生颓废 提交于 2019-12-01 05:30:46

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

Hope this will help

have you tried echo instead of die?

echo '{"jsonrpc" : "2.0", "result" : "'.$_REQUEST['unitID'].'", "id" : "id"}';

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
            }
        }
    });
}
uploader.bind('FileUploaded', function (up, file, res) {
  var res1 = res.response.replace('"{', '{').replace('}"', '}');
  var objResponse = JSON.parse(res1);
  alert(objResponse.fn);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!