2017-01-16 6 views
0

Я ищу Простую проверку с помощью текстового файла.проверка с текстовым файлом с использованием JavaScript

Например:

verification.txt

Text: ABC5864 

на основе пользовательского ввода, если это правильно, то это позволит войти в противном случае выводит сообщение об ошибке:

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

Здесь мой код:

$(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

Попробуйте

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

 Смежные вопросы

  • Нет связанных вопросов^_^