0

I am using jQuery 2.0 with html5Uploader plugin to upload files via ajax, and I have following problem (stick on this one with me). Every time when file is being uploaded, this element is being appended to the upload box:

var fileTemplate = "<div ole=\"id_image\"  id=\"{{id}}\" class=\"clearfix fl slika_prv\" >";
        fileTemplate += "<div class=\"preview\"></div>";
        fileTemplate += "<div class=\"filename\">{{filename}}</div>";
        fileTemplate += "<a href=\"" + url_tmp_delete  + "\"  class=\"image_delete_tmp\">Obriši Sliku</a>";
        fileTemplate += "</div>";

And when the upload is successful, this function is being called:

onSuccess : function(e, file, data) {
                $('.image_delete_tmp').attr('data-id', data);
                var img_delete = $('.image_delete_tmp');
                delete_image(img_delete, 'tmp');
            }

It adds id data to the a tag. This a tag is for deleting the uploaded file, and data is name of the file being uploaded (response from the server). My problem is how to add unique id to image that is being uploaded (at the moment all a tag have same id (of the last uploaded file))? I know that this is confusing question, but at the moment this is best I can do :(.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sasha
  • 8,521
  • 23
  • 91
  • 174
  • I would suggest to you generate a file id in the server and use it here. – Joqus Aug 29 '13 at 15:28
  • That is what I did. But only last id is added to the a tag - because function is taking all a tags with class image_delete_tmp, and adds the id value to them. I am trying to find a way not to write id only once to the a tag. I think I gave the answer to myself... – Sasha Aug 29 '13 at 15:31

0 Answers0