2017-06-27 17 views
0

パスワードが正しくなく、jQueryを使用して必須フィールドが指定されていない場合は、alertが必要です。
私はいくつかの論理に打たれました。事前に外部のjavascriptからのログイン通知

おかげ..

のindex.php

<input class="form-control" type="text" required="" id = "stu_id" placeholder=" Id"> 
<input class="form-control" type="password" required="" id = "passwd" placeholder="Password"> 

<a href="javascript:void(0);" onclick="stu_login();" type="submit">Log In</a> 

//here i want to display alert if required fields and password is incorrect 
<div align ="right" id = "login_status"> </div> 

これは私のlogin_check.js私は簡単からのメッセージを表示することができ、コードで

function stu_login() { 
    var stu_id = $("#stu_id").val(); 
    var stu_passwd = $("#passwd").val(); 

    if(stu_id == "") 
    { 
    $("#login_status").html('<div class="info" id="sa-basic">Please enter your ID to proceed.</div>'); 
    $("#stu_id").focus(); 

    else if(stu_passwd == "") 
    { 
     $("#login_status").html('<div class="info" id="sa-basic">Please enter 
     your account password to go.</div>'); 
     $("#passwd").focus(); 
    } 
    else 
    { 
     var dataString = 'stu_id=' + stu_id + '&passwd=' + stu_passwd + '&page=users_login'; 
     $.ajax({ 
     type: "POST", 
     url: "login_check.php", 
     data: dataString, 
     cache: false, 
     beforeSend: function() 
     { 
      $("#login_status").html('<br clear="all"><br clear="all"><div 
      align="left"><font style="font-family:Verdana, Geneva, sans-serif; 
      font-size:15px; color:black;">Please wait</font> <img 
      src="images/loadings.gif" alt="Loading...." align="absmiddle" 
      title="Loading...."/></div><br clear="all">'); 
     }, 
     success: function(response) 
     { 
      var response_brought = response.indexOf('login_process_completed_successfully=yes'); 
      if (response_brought != -1) 
      { 
      $("#login_status").html(''); 
      //window.location.replace(response); 
      window.location ="home.php"; 
      } 
      else 
      { 
      $("#login_status").fadeIn(1000).html(response); 
      } 
     } 
     }); 
    } 
    } 

ですlogin_check.jsindex.htmlですが、 alert.jsからアラートを通知する方法はわかりません。login_check.jsのメッセージを置き換えて、ポップアップアラートを作りたいと思います。ここで

$(#1 login_status)の.htmlに変更

!function ($) { 
"use strict"; 

var SweetAlert = function() { 
}; 

SweetAlert.prototype.init = function() { 

    //Basic 
    $('#sa-basic').click(function() { 
    swal("Here's a message!"); 
    }); 
    //init 
    $.SweetAlert = new SweetAlert, $.SweetAlert.Constructor = SweetAlert 
}(window.jQuery), 

//initializing 
function ($) { 
    "use strict"; 
    $.SweetAlert.init() 
}(window.jQuery); 

答えて

関連する問題