У меня есть это JSON сообщение проверки при загрузке изображения с использованием AJAX:
{
"status": "error",
"message": {
"image": ["The image must be a file of type: jpeg, jpg, png, gif.", "The image field is required."]
}
}
и мне нужно показать эту ошибку в bootstrap модальном окне:
$('.crop_image').click(function (event) {
$image_crop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function (response) {
$.ajax({
url: "{{ Route('admin.admin_users.image_croppie') }}",
type: "POST",
dataType: "json",
data: {
"image": response
},
success: function (response) {
if (response.status === 'error') {
$('#uploadimageModal').animate({
scrollTop: $('#uploaderror').offset().top
}, 500);
$.each(response.message, function (index, message) {
$('#uploaderror').css('display', 'block').html(message);
});
} else {
$('#uploadimageModal').modal('hide');
//$("#myimg").removeAttr("src").attr("src", response.message);
//$('#uploaded_image').removeAttr('src');
$("#uploaded_image").fadeTo(500, 0.30, function () {
$('#uploaded_image').attr('src', response.message + '?timestamp=' + new Date().getTime());
}).fadeTo(250, 1);
//$('#uploaded_image').html(response.message);
}
}
});
})
});
В действии я вижу окно ошибки в модальном виде, например:
В моем случае ошибок нет в списке (для каждой ошибки). Мне нужно перечислить несколько ошибок (отдельные ошибки). Я думаю, что моя $.each
функция не работает. Как решить эту проблему?