2

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

And have an onComplete:

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

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

Thanks

UPDATING

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

both of the alerts don't run?

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

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

1
  • response right now says [object object] Commented Oct 24, 2010 at 23:58

4 Answers 4

4

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

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

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

Sign up to request clarification or add additional context in comments.

3 Comments

Maybe rails isn't sending back the right response? I have it harded coded. Uploadify wants JSON right? render :json => { :result => 'success', :album_id => 31313113 }
Sorry! you should use alert(response.responseText)
If you returns JSON data then you have to parse. But if you just return the album id as a value then this code works
1

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.

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

Comments

0

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.

$('#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.
    }
});

Comments

0

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

jsonObject = jQuery.parseJSON(response);

//Then access the object property or method after

alert(jsonObject.album_id);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.