RuslanK

ajax

Feb 19th, 2022
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $( document ).ready(function() {
  2.     $("#name").change(
  3.         function(){
  4.             var name = document.getElementById("name").value;
  5.                        
  6.            
  7.             if (name.length == 0){
  8.                 alert ("Нужно заполнить имя");
  9.             }else{
  10.                 sendAjaxForm('result_form', 'ajax_form', '/action_ajax_form.php');
  11.             }
  12.            
  13.             return false;
  14.         }
  15.     );
  16. });
  17.  
  18. function sendAjaxForm(result_form, ajax_form, url) {
  19.     var name = "test";
  20.    
  21.     $.ajax({
  22.         url:     "action_ajax_form.php", //url страницы (action_ajax_form.php)
  23.         type:     "POST", //метод отправки
  24.         dataType: "html", //формат данных
  25.         data: name,  // Сеарилизуем объект
  26.         success: function(response) { //Данные отправлены успешно
  27.             alert ("данные отправлены");
  28.         },
  29.         error: function(response) { // Данные не отправлены
  30.             $('#result_form').html('Ошибка. Данные не отправлены.');
  31.         }
  32.     });
  33. }
Advertisement
Add Comment
Please, Sign In to add comment