Trying to upload an image file with preview using Jquery. It's working and I got the preview, but when I click on the upload button I saw an error message
Uncaught RangeError: Maximum call stack size exceeded
in the console.
Here is the code:
$(document).ready(function() {
var readURL = function(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('.profile-image').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$(".file-upload").on('change', function() {
readURL(this);
});
$(".upload-button").on('click', function() {
$(".file-upload").click();
});
});
Select Image