$('.pop-up-one').on('submit', function(e) {
e.preventDefault();
var $form = $(this);
$.ajax({
type: 'POST',
url: $form.attr('action'),
data: $form.serialize(),
success: function (response) {
response = JSON.parse(response);
if (response.type && response.type === 'success') {
$form[0].reset();
} else {
}
},
error: function (response) {
}
});
});
<form class="pop-up-one" action="ajax-contact-form.php">
<input type="text" placeholder="Введите ваше имя" name="name" required>
<input type="text" placeholder="Введите ваш телефон" name="message">
<input type="text" placeholder="E-mail" name="email" required>
<button type="submit" class="button-pop-up">Отправить</button>
</form>
//serialize data function
function objectifyForm(formArray) {
var returnArray = {};
for (var i = 0; i < formArray.length; i++){
returnArray[formArray[i]['name']] = formArray[i]['value'];
}
return returnArray;
}
$.ajax({
type: 'POST',
url: $form.attr('action'),
data: objectifyForm($form.serialize()),
success: function (response) {