-3

我对如何检查存储在数组中的用户名和密码有疑问,我不知道如何使用ajax

HTML

<input type="text" id="tuser" /><br>
<input type="password" id="password" /><br>
<input type="submit" id="send" value="Send"/><br>
<input type="range" id="rg" name="rg" min="0" max="50"/><br>

<script>
    $(document).ready(function() {
        $("#tuser").focus();$("#rg").hide();

        });     
        $("#tuser").keyup(function() {
            $.ajax({type:"GET",
                url: "validate.php",
                data:"names="+$("#tuser").val()+"pass="+$("#password").val(),
                success:function(data) {
                    if (data=="Error") {
                        $("rango").hide();
                    } else {
                        $("#rg").show();

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

PHP 验证(这里我知道如何发送名称但我不知道如何发送密码)

if($_GET['names']!=''){
  $personal=array("Kaoru"=>'hello1',"Megumi"=>'hello2',"Naoko"=>'hello3');
  foreach ($personal as $key=>$value){

      if(isset($personal['$key'])&& $personal['$key']=='$value') {
      echo $apersonal[$_GET['names']];
  } else {
      print "Error";


}}}?>

感谢进步ssssssss

4

1 回答 1

1
$.ajax({type:"POST",   
data:"names="+$("#tuser").val()+"&pass="+$("#password").val(),

if( isset($_POST['names']) && !is_empty($_POST['names']) ){
  $personal=array("Kaoru"=>'hello1',"Megumi"=>'hello2',"Naoko"=>'hello3');      

      if(isset($personal[$_POST['names']])&& $personal[ $_POST['names'] ] == $_POST['pass']) {
        echo "Logged IN";
      }else{
         echo "Wrong user or pass";
      }

  } else {
      print "Error";


}
于 2012-10-01T01:17:47.047 回答