jQuery Uploadify - How to use onComplete?
Solution 1
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.
Solution 2
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.
TheExit
Updated on April 04, 2020Comments
-
TheExit about 4 years
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 }
-
TheExit over 13 yearsMaybe rails isn't sending back the right response? I have it harded coded. Uploadify wants JSON right? render :json => { :result => 'success', :album_id => 31313113 }
-
Lorenzo over 13 yearsSorry! you should use
alert(response.responseText)
-
Lorenzo over 13 yearsIf you returns JSON data then you have to parse. But if you just return the album id as a value then this code works