Skip to content

Instantly share code, notes, and snippets.

@igoogle
Last active April 10, 2018 13:42
Show Gist options
  • Save igoogle/e177a77fe2b0a457f747f07218c66872 to your computer and use it in GitHub Desktop.
Save igoogle/e177a77fe2b0a457f747f07218c66872 to your computer and use it in GitHub Desktop.
// Отправка файла через popup-форму, с помощью ajax
$(document).on('submit', '[data-id="feedback"]', function(e) {
e.preventDefault();
const $t = $(this);
const formData = new FormData($('form[data-id=feedback]')[0]);
$.ajax({
type: 'POST',
url: '/local/ajax/actions/feedback.php',
data: formData,
contentType: false,
processData: false,
dataType: 'json',
beforeSend: function () {
},
success: function (res) {
},
error: function (res) {
}
}).done(function(res) {
// Есть ошибки
if(res.ERROR_FLAG === 'Y' && res.ERROR_FIELD_CODE.length > 0) {
res.ERROR_FIELD_CODE.forEach(function(item, i, arr) {
$('[name='+item+']', $t).addClass('error');
});
}
});
$(function() {
console.log( "ready!" );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment