|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
function send(event, php){ $(event.target).addClass('off'); console.log("Отправка запроса"); event.preventDefault ? event.preventDefault() : event.returnValue = false; var req = new XMLHttpRequest(); req.open('POST', php, true); req.onload = function() { if (req.status >= 200 && req.status < 400) { json = JSON.parse(this.response); // Для internet explorer 11 //console.log(json); // ЗДЕСЬ УКАЗЫВАЕМ ДЕЙСТВИЯ В СЛУЧАЕ УСПЕХА ИЛИ НЕУДАЧИ if (json.result == "success") { // Если сообщение отправлено $(event.target).removeClass('off'); //alert("Сообщение отправлено"); Swal.fire({ position: 'center', icon: 'success', html: 'Сообщение отправлено!', showConfirmButton: false, showCloseButton: true, showCancelButton: false, customClass: { popup: 'success-modal' } }); } else { // Если произошла ошибка alert("Ошибка. Сообщение не отправлено"); } // Если не удалось связаться с php файлом } else {alert("Ошибка сервера. Номер: "+req.status);}}; // Если не удалось отправить запрос. Стоит блок на хостинге req.onerror = function() {alert("Ошибка отправки запроса");}; req.send(new FormData(event.target)); } |
