jQuery/PHP: 使用 Uikit 组件通过 $.ajax 提交

jQuery/PHP: submit from via $.ajax using components of Uikit

我正在尝试为 $ .ajax 传递一个表单,但是当我到达成功的部分时:函数(数据)块....我不是这方面的专家,只是如果有人好心解释 poderme 如何发送“通知”,请开始练习编程,这是我的代码:

<script>
$(function  () {    
  $("#contacto_web").submit(function(e) {
    e.preventDefault(); 
    $.ajax({
        url : "contacto_web.php",
        type : "POST",
        data : {
          $("#contacto_web").serialize();
        },
        before : function () {

        },
        success : function (data) {
          if(data == "si_enviado"){                             
              $UIkit.notify({
                  message : 'Bazinga!',
                  status  : 'info',
                  timeout : 5000,
                  pos     : 'top-center'
              }); 
          }else if(data == "no_enviado"){
              $UIkit.notify({
                  message : 'Bazinga!',
                  status  : 'danger',
                  timeout : 5000,
                  pos     : 'top-center'
              });
          }
        },
        error : function () {

        },
    });
  });      
});
</script>

Uikit 框架Link:

Component Notify

php代码:

<?php 

if(filter_input_array(INPUT_POST)){

  $nombres = filter_input(INPUT_POST, "nombres");
  $apellidos = filter_input(INPUT_POST, "apellidos");
  $tlfno1 = filter_input(INPUT_POST, "tlfno1");
  $tlfno2 = filter_input(INPUT_POST, "tlfno2");
  $email1 = filter_input(INPUT_POST, "email1");
  $email2 = filter_input(INPUT_POST, "email2");

  $nombre_razonsocial = filter_input(INPUT_POST, "nombre_razonsocial");
  $pais = filter_input(INPUT_POST, "pais");
  $direccion = filter_input(INPUT_POST, "direccion");
  $sms_form = filter_input(INPUT_POST, "sms_form");

  $to = "diego.cardenas@udatabox.com";
  $title = "Correo de contacto desde la pagina web";
  $headers = "From: $email1" . "\r\n";
  $message ="
    Contacto desde la pagina web\n
    $nombres $apellidos\n    
    Telefono $tlfno1 | Movil $tlfno2\n
    Correo principal $email1, Correo alternativo $email2\n\n
    Nombre / Razon social $nombre_razonsocial\n
    Pais de procedencia $pais\n
    Direccion $direccion\n
    Mensaje\n
    $sms_form   
  ";

  if(mail($to,$title,$message,$headers)){
        echo "si_enviado";        
      }else{
        echo "no_enviado";
      }

}

解决方案:

$(function() {
  $("#contacto_web").on("submit", function(event) {
    event.preventDefault();
    $('#output').text(( $( this ).serialize() ));
    UIkit.notify({
                          message : 'Enviando mensaje...',
                          timeout : 5000,
                          status  : 'success'
                      }); 
    $.ajax({
                url : "contacto_web.php",
                type : "POST",
                data : $(this).serialize(),
                before : function () {

                },
                success : function (data) {
                  if(data == "si_enviado"){                         
                      UIkit.notify({
                          message : 'Mensaje enviado, Gracias!',
                          status  : 'info',
                          timeout : 5000,
                          pos     : 'top-center'
                      }); 
                  }else if(data == "no_enviado"){
                      UIkit.notify({
                          message : 'Mensaje no enviado!',
                          status  : 'info',
                          timeout : 5000,
                          pos     : 'top-center'
                      });
                  }
                },
                error : function () {

                },
            });
  });
});