Here is my form (basic upload) :
<span class="btn btn-success fileinput-button">
<span>Select files...</span>
<input id="fileupload" type="file" name="files[]" multiple>
</span>
<br>
<div id="files" class="files"></div>
Here is my script :
$(function () {
$('#fileupload').fileupload({
url: 'server/php/',
dataType: 'json',
add: function (e, data) {
data.context = $('<p/>').text('Uploading...').appendTo('#files');
data.submit();
},
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').html('<a href="#" class="text-danger delete" data-type="' + file.deleteType + '" data-url="' + file.deleteUrl + '" title="Delete">Delete</a>').appendTo('#files');
});
}
});
});
My upload is OK but when I click on the DELETE link, nothing happens. It seems like this link has no effect. Maybe I missed to include something ?
Any idea ?
Unless I'm missing something, you haven’t set up an event listener on the link.
$('#files').on('click', 'a', function (e) {
e.preventDefault();
var $link = $(this);
var req = $.ajax({
dataType: 'json',
url: $link.data('url'),
type: 'DELETE'
});
req.success(function () {
$link.closet('p').remove();
});
});