I've been messing around with an Ajax upload tutorial I found here. I'm trying to check if the server returned "error"
as the status. I found it out, it's data.result
. When I do console.log(data)
when data
is defined, result
is {"status":"error"}
as expected, but when I try to call data.result
in the same function, it returns undefined. I tried everything, defining it in a global variable when it's not undefined, and even passing it to another function. Here's what I have:
progress: function(e, data){
// calc the completion percentage of the upload
var progress = parseInt(data.loaded / data.total * 100, 10);
console.log(data);
/* console log:
Object {disabled: false, create: null, dropZone: b.fn.b.init[1], pasteZone: b.fn.b.init[1], replaceFileInput: true…}
(more values)
result: "{"status":"error"}"
(more values)
*/
// update hidden input field and trigger a change
data.context.find('input').val(progress).change();
if(progress == 100){
updateProgress(data);
}
},
// ... later on in the file ...
function updateProgress(data){
console.log(data);
if(JSON.parse(data.result).status === 'error'){
data.context.addClass('error');
}else{
data.context.removeClass('working');
$('#drop').fadeOut(function(){
$('#drop').remove();
if(debug === 0){window.location = 'http://datastorage.iquestria.net/images/'+data.files[0].name+'?v2';}
});
}
}