php - 登录只是刷新页面 php html

标签 php html css mysql

我的登录页面自行刷新。它已经工作了一段时间,当我尝试对问题进行一些更改时,我删除了更改并尝试了不同的计算机和浏览器,但仍然做同样的事情。所以我无法登录我尝试了所有可能的方法,但没有成功。 这是我的代码。

<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>King Musa Transport System</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/square/blue.css">

    <!-- jQuery 2.1.4 -->
    <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
     <!-- jQuery -->
    <script src="bootstrap/jquery/jquery.min.js"></script>

    <script src="bootstrap/js/bootstrap.min.js"></script>
    <!-- iCheck -->

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body class="hold-transition login-page">
    <div class="login-box">
      <div class="login-logo">
        <a href="index.php"><b>Powered by King Musa Systems.
      </div><!-- /.login-logo -->
      <div class="login-box-body">
        <p class="login-box-msg">Sign in to start your session</p>
        <form class="form-horizontal"   id="myform" method="post">
          <div class="form-group has-feedback">
            <input type="text" class="form-control" id ="username" name="username">
            <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
          </div>
          <div class="form-group has-feedback">
            <input type="password" id ="password" name = "password" class="form-control">
          </div>
          <div class="row">
            <div class="col-xs-8">
              <div class="checkbox icheck">
                <label>
                </label>
              </div>
            </div><!-- /.col -->
            <div class="col-xs-4">
              <button type="submit" name ="submit" id ="submit_login" class="btn btn-primary btn-block btn-flat">Sign In</button>
            </div><!-- /.col -->
          </div>
        </form>

        <div class="social-auth-links text-center">
        </div><!-- /.social-auth-links -->
         <span id="showerrors"></span>
<div class ="showerrors"></div>
        <a href="#">I forgot my password</a><br>
        <a href="register.html" class="text-center">Register a new membership</a>

      </div><!-- /.login-box-body -->
    </div><!-- /.login-box -->


    <script>
    $(document).ready(function(){
    $("#showerrors").css('display', 'none', 'important');
     $("#submit_login").click(function(){   
          username=$("#username").val();
          password=$("#password").val();
          if(username==""){
                    $(".showerrors").html("<p style='color:red'>please type  username</p>");

                     }
         else if(password==""){
                     $(".showerrors").html("<p style='color:red'>please type  password</p>");

                     }
          $.ajax({
           type: "POST",
           url: "dologin.php",
            data: "username="+username+"&password="+password,
           success: function(datasender){    
            //debugger;
            if(datasender)    {
            //$(".showerrors").html(datasender.message);
//alert(datasender.message);
             window.location="index.php";
            }
            else {

            }
           },
           beforeSend:function()
           { 
            $("#showerrors").css('display', 'inline', 'important');
            $("#showerrors").html("<p style='color:green'>Loading...")
           }
          });
        return false;
    });
});

//Read more: http://www.ondeweb.in/ajax-login-form-with-jquery-and-php/#ixzz3d9UpBgG7

        </script>


  </body>
</html>

最佳答案

您正在使用 jquery 来处理您的登录功能,但您没有阻止默认执行​​。

这部分

$("#submit_login").click(function(){   
      username=$("#username").val();
      password=$("#password").val();

应该包含

$("#submit_login").click(function(event){
      event.preventDefault();
      username=$("#username").val();
      password=$("#password").val();

为了阻止浏览器发布您的表单。

您可以在 jQuery documentation 中阅读更多相关信息

关于php - 登录只是刷新页面 php html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48784526/

相关文章:

php - 使用 php 调整图像大小

php - 位置感知移动应用程序,需要有关我应该使用哪些技术的建议

html - 形成文本框溢出和文本位置的问题

javascript - 异常 : Failed to execute 'querySelector' on 'Document' :

html - 将 INPUT 与 div 完美对齐

php - 在 Apache 服务器上使用 WebSocket

php - Laravel 电子邮件验证一键禁用和启用

php - 使用 Symfony 3 cURL 到 DropBox

javascript - 在 bootstrap 中运行自定义 jquery 文件但失败

css - 从使用 Font Awesome 图标的免费 jqgrid 工具栏按钮中删除 Chrome 中的跳舞效果