I'm using One Click Upload (ocupload.js) to upload attachments with a custom mail form to a temp folder on my server.
After each upload, a small label with the filename is being added to a dropzone. Each label has a little remove button. When pressing the remove button, the attachment file is removed from the temp folder and the label is removed.
Basic attachment UI stuff.
Nog here's my problem: When clicking on the remove button, the attachment is removed from the temp folder and the corresponding label is removed from the dropzone, so my Ajax call works fine. But after this, every ajax call i try, fails. Not only removing attachments but also uploading new ones. There is just no response at all.
The upload script:
$("#attachment").livequery(function(){
$(this).upload({
name: 'xfile',
action: '/ajax/upload',
params: {action:'attachment',folder:'/tmp/mails/new'},
onSelect: function(){
console.log('file selected');
},
onSubmit: function() {
console.log('file submitted');
},
onComplete: function(response){
response = jQuery.parseJSON(response);
var $attachment = $('#attachment_dropzone .attachment.template').clone();
//fill template
$attachment.find('.name').html(response.filename);
$attachment.attr('data-filename',response.filename);
$attachment.attr('data-path',response.path);
//add label
$attachment.removeClass('template');
$attachment.removeAttr('style');
$('#attachment_dropzone').append($attachment.clone());
}
})
});
and the remove handler
$('#attachment_dropzone .attachment .remove').livequery(function(){
$attachment = $(this).parent().parent();
$(this).on('click',function(){
console.log('start remove');
$.post('/ajax/action', { action: 'remove_attachment', filename: $attachment.data('filename'), path: $attachment.data('path') }, function(data){
console.log('remove callback');
if (data == 'success'){
console.log('remove success');
$attachment.remove();
}else{
alert(data);
}
})
})
});
As you can see, i'm using livequery.js to make sure the scripting works on dynamically added containers as well.
I can upload as many attachments i want, no problem there, when i remove one, the whole ajax story ends