English 中文(简体)
jQuery Uploadify-如何使用onComplete?
原标题:jQuery Uploadify - How to use onComplete?

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

并有一个onComplete:

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

我的服务器正在发送回album_id。。。我如何在响应中访问它?

谢谢

更新

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

两个警报都不运行?

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

渲染:json=>;{:结果=>;成功,:白蛋白_id=>!31313113}

最佳回答

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

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

需要返回false以避免触发默认函数。

问题回答

我相信回复是:

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

很明显,无论你回来什么,都会得到回应。在我的情况下,它是一个flickrphotoID,因为我的uploadify脚本正在将文件上传到Flickr,然后等待ID。

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

上面的答案是正确的,为您指明了onComplete方法。我唯一要补充的是,请你发布你的整个上传通话。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.
    }
});

//您必须首先将其作为一个整体对象进行解析

jsonObject=jQuery.parseJSON(响应);

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

alert(jsonObject.album_id);





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签