When I click on the "Send" button, need to get all the downloaded files (images) in order to transfer them to the server later. I do not know how to do it right.
It is worth noting that there is a deletion of the image by clicking on it. So just add the loaded objects to the list is unlikely to succeed. I think dictionaries would be useful here if they are in jquery.
$('.product_images_button').click(function() {
$('.product_images').click()
});
function readURL(input) {
var reader = new FileReader();
reader.onload = function(e) {
$('.blah').last().attr('src', e.target.result).css('width', '150px').css('opacity', '0.9');
}
reader.readAsDataURL(input.files[0]);
$('.media_preview_wrap').append('<img class="blah" src="">');
$(".product_images").val("");
}
$(".product_images").change(function() {
readURL(this);
});
$(document).on('click', '.blah', function() {
$(this).remove()
})
$('#id_submit').click(function() {
var data = {
}
console.log(data)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="media_preview_wrap">
<div class="addPhoto">
<div class="addPhotoHeader">
<button type="button" class="button product_images_button">Upload image</button>
</div>
</div>
</div>
<input type="file" name="image" style="display: none" required="" class="product_images" id="">
<button id="id_submit" type="button">Send</button>
Aucun commentaire:
Enregistrer un commentaire