jQuery Uploadify - 如何使用 onComplete?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4011074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:29:46  来源:igfitidea点击:

jQuery Uploadify - How to use onComplete?

jqueryuploadify

提问by TheExit

I'm using uploadify: http://www.uploadify.com/

我正在使用上传:http://www.uploadify.com/

And have an onComplete:

并有一个 onComplete:

onComplete: function(response) {
alert(response);
},

My server is sendin back album_id... How do I access that in the response?

我的服务器发送回专辑 ID... 我如何在响应中访问它?

Thanks

谢谢

UPDATING

更新

        onComplete: function(response) {
            jsonObject = jQuery.parseJSON(response.response);
            alert (jsonObject);
            alert(jsonObject.album_id);
        },

both of the alerts don't run?

两个警报都不运行?

UPDATE 2RAils code that is sending back the JSON? Maybe this is the issue?

更新 2发送回 JSON 的 RAils 代码?也许这是问题?

render :json => { :result => 'success', :album_id => 31313113 }

渲染:json => {:结果 => '成功',:专辑 ID => 31313113 }

回答by Lorenzo

the onComplete is sending four arguments. So you function should be like this one:

onComplete 发送四个参数。所以你的功能应该是这样的:

onComplete: function(event, queueID, fileObj, response, data) {
    alert(response.responseText);
    return false;
},

The return false is needed to avoid to trigger the default function.

需要返回 false 以避免触发默认功能。

回答by Hyman Marchetti

I believe the response sent back is:

我相信发回的回复是:

 function UploadComplete(event, queueID, fileObj, response, data) { }

Response would obviously be whatever you're returning. In my case it was a flickrphotoID because my uploadify script was uploading the file to Flickr then waiting for the ID.

响应显然是您返回的任何内容。就我而言,它是一个 flickrphotoID,因为我的uploadify 脚本正在将文件上传到 Flickr,然后等待 ID。

If your response is a json object, then you'll need to parse it out.

如果您的响应是一个 json 对象,那么您需要解析它。

回答by hardba11

The answers above are correct in pointing you towards the onComplete method. The only thing I have to add, is to ask you to post your entire uploadify call. The onComplete needs to be built in your call. It should look like something like this.

上面的答案正确地将您指向 onComplete 方法。我唯一要补充的是,请您发布整个uploadify 电话。onComplete 需要构建在您的调用中。它应该看起来像这样。

$('#sampleFile').uploadify({
        'uploader': 'include/uploadify/uploadify.swf',
        'script': 'add_list.php',
        'scriptData': {'mode': 'upload'},
        'fileDataName': 'newUpload',
        'folder': '/work/temp/uploads',
        'cancelImg': 'images/cancel.png',
        'queueID': 'uploadQueue',
        'onComplete': function (event, queueID, fileObj, response, data) {
        // A function that triggers when a file upload has completed. The default 
        // function removes the file queue item from the upload queue. The 
        // default function will not trigger if the value of your custom 
        // function returns false.
        // Parameters 
        //    event: The event object.
        //    queueID: The unique identifier of the file that was completed.
        //    fileObj: An object containing details about the file that was selected.
        //    response: The data sent back from the server.
        //    data: Details about the file queue.
    }
});

回答by Einlanzer

//You have to parse it first as a whole object

//你必须首先将它解析为一个完整的对象

jsonObject = jQuery.parseJSON(response);

jsonObject = jQuery.parseJSON(响应);

//Then access the object property or method after

//然后访问对象的属性或方法之后

alert(jsonObject.album_id);

警报(jsonObject.album_id);