2017-02-25 8 views
0

私のAjaxコードがエラーを返さないように、私はモーダルを得るようにしたいと思います。私のコードはすべて完璧に動作しています。一度エラーがなければモーダルポップアップを作成する方法を知る必要があります。私はajaxの成功を持っています:関数ですが、現時点ではボタンがクリックされたときにのみ動作するので、このコードがどのように機能するかはわかりません。PHP - 登録成功時にSweetAlertモーダルポップアップを表示する(AJAX)

私はSweetAlert JSファイル

を使用してい

マイコード:ボタンをクリックする

作業モーダル:

<script> 
    !function(e){ "use strict"; 
    var t = function(){}; 
    t.prototype.init = function() { 
     e("#sa-success").click(function() { 
     swal("Registration Successful","Your registration was successful! Check your email and click on your activation link to be able to access your account.","success") 
     } 
     ) 
    },e.SweetAlert=new t,e.SweetAlert.Constructor=t}(window.jQuery),function(e){"use strict";e.SweetAlert.init()}(window.jQuery); 
</script> 

私のAJAXの登録コード一度msg = ''を入力するとモーダルポップアップを作りたい:

<script> 
     $(document).ready(function() { 

    jQuery.validator.addMethod("noSpace", function(value, element) { 
    return value.indexOf(" ") < 0 && value != ""; 
    }, "Spaces are not allowed"); 

      $("#registered_form").submit(function() { 

       if ($("#registered_form").valid()) { 
        var data1 = $('#registered_form').serialize(); 
        $.ajax({ 
         type: "POST", 
         url: "inc/pgs/register.php", 
         data: data1, 
         success: function(msg) { 
          console.log(msg); 
          if(msg == '') { 
           //setTimeout("window.location.href='login.php';",4000); 
          } else { 
           $("#result").html('<div class="alert alert-danger"><button type="button" class="close"></button>' + msg +'</div>').slideDown(100); 
           window.setTimeout(function() 
           { 
            $(".alert").fadeTo(500, 0).slideUp(500, function(){ 
             $(this).remove(); 
            }); 
           }, 3000); 
          } 
         } 
        }); 
       } 
       return false; 
      }); 
     }); 
    </script> 

答えて

0

すべてソートされています。 SweetAlertのマニュアルを見て、どのように動作するかを見なければなりませんでした。私は前にチェックしておくべきだった。

私は使用していた:

swal("Registration Success!", "Your registration was successful! Check your email and click on your activation link to be able to access your account.", "success"); 
関連する問題