2017-01-16 8 views
0

私はテキストファイルを使用した簡単な検証をお探しです。JavaScriptを使用したテキストファイルによる確認

例えば

:ここ

<input name="myverification" id="myverification" type="verification" class="form-control" placeholder="verification"> 

:それは、正しいかどう

ユーザー入力に基づいて

Text: ABC5864 

verification.txt、それはそれ以外の場合は、ログインエラーメッセージを表示することができます私のコードです:

$(document).ready(function() { 
 
    "use strict"; 
 
    $("#submit").click(function() { 
 

 
     var username = $("#myusername").val(), password = $("#mypassword").val(); 
 

 
     if ((username === "") || (password === "")) { 
 
      $("#message").html("<div class=\"alert alert-danger alert-dismissable\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>Please enter a username and a password</div>"); 
 
     } else { 
 
      $.ajax({ 
 
       type: "POST", 
 
       url: "checklogin.php", 
 
       data: "myusername=" + username + "&mypassword=" + password, 
 
       dataType: 'JSON', 
 
       success: function (html) { 
 
        //console.log(html.response + ' ' + html.username); 
 
        if (html.response === 'true') { 
 
         //location.assign("../index.php"); 
 
         location.reload(); 
 
         return html.username; 
 
        } else { 
 
         $("#message").html(html.response); 
 
        } 
 
       }, 
 
       error: function (textStatus, errorThrown) { 
 
        console.log(textStatus); 
 
        console.log(errorThrown); 
 
       }, 
 
       beforeSend: function() { 
 
        $("#message").html("<p class='text-center'><img src='images/ajax-loader.gif'></p>"); 
 
       } 
 
      }); 
 
     } 
 
     return false; 
 
    }); 
 
});
 <form class="form-signin" name="form1" method="post" action="checklogin.php"> 
 
     <h2 class="form-signin-heading">Please sign in</h2> 
 
     <input name="myusername" id="myusername" type="text" class="form-control" placeholder="Username" autofocus> 
 
     <input name="myverification" id="myverification" type="verification" class="form-control" placeholder="verification"> 
 
     <input name="mypassword" id="mypassword" type="password" class="form-control" placeholder="Password"> 
 
     <button name="Submit" id="submit" class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> 
 
     <div id="message"></div> 
 
     </form>

事前

答えて

0

のおかげで、このコードは、TXTファイルを読み込み、値を取得することができますどのようにこの

function checkInput(input_id) { 
     input_value = jQuery('#' + input_id).val(); 
     if ((input_value == "") || (input_value == null)) { 
      jQuery('#' + input_id + '_error').html('Please fill in 
!'); 
      return 0; 
     } else { 
      jQuery('#' + input_id + '_error').html(''); 
      return 1; 
     } 

    } 
+0

を試してみてください? – Jomla

関連する問題