2

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 ?

1
  • what errors do you see in your console ? Commented Mar 13, 2015 at 15:49

2 Answers 2

5

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();
  });
});
Sign up to request clarification or add additional context in comments.

2 Comments

My mistake... You rock !
Could you please tell me how to remove delete link from response GUI
2

you might have resolved your problem but just adding my answer for any new solution seeker.

you don't need to make a delete request manually as done by @rglyall, just setup the html structure properly and Jquery-file-upload will take care of it itself.

change

<a href="#" class="text-danger delete" data-type="' + file.deleteType + '" data-url="' + file.deleteUrl + '" title="Delete">Delete</a>

to

<button class="text-danger delete" data-type="' + file.deleteType + '" data-url="' + file.deleteUrl + '" title="Delete">Delete</button>

you need to make sure following things exist to library automatically handle this i.e

  1. Html element has to be 'button'.
  2. This button has to have a class of 'delete'.
  3. This button has to have 'data-type'.
  4. This button has to have 'data-url'.

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.