search

Home  >  Q&A  >  body text

Xiaobai was watching a video on how to quickly develop an enterprise website using tp5 and encountered a problem.

Why does my front-end never respond when I click the login button? No error is reported either. Is there a mistake in writing jquery? It is almost a complete copy of Mr. Zhu’s. Why still no response? Public documents also introduce JQUERY. Please give me some guidance. The following is the source code of the view layer local.html file

{include file='public/header' /}

   

  <body style="background-color: #393D49 ">

" "layui-icon x-login-close">

                                                                                                                                                             ">

                                                                                                                                                                                         < li style="background-color: #EA569A;" color="#EA569A">

                                                                                                   " color="#393D49">

                                                                                                                     ; div class = "x-mid"> "">

                                                                                       ;

                <div class="input">

                    <form class="layui-form">

                        <div class="layui-form-item x-login-box">

                            <label for="username" class="layui-form-label">

                                <i class="layui-icon"></i>

                            </label>

                            <div class="layui-input-inline">

                                <input type="text" id="name" name="name" class="layui-input" placeholder="username" required="">

                            </div>

                        </div>

                        <div class="layui-form-item x-login-box">

                            <label for="password" class="layui-form-label">

                                <i class="layui-icon"></i>

                            </label>

                            <div class="layui-input-inline">

                                <input type="password" id="password" name="password"  class="layui-input" placeholder="******" required="">

                            </div>

                        </div>

                        <div class="layui-form-item" id="loginbtn">

                            <button  lay-filter="save" class="layui-btn" lay-submit="" type='button' id="loginbt">

                                登 录

                            </button>

                        </div>

                    </form>

                </div>

            </div>

        </div>

        <p style="color:#fff;text-align: center;">Copyright © 2017.Company name All rights X-admin </p>

        {include file="public/script" /}

        <script>

            layui.use(['form'],

            function() {

                $ = layui.jquery;

                var form = layui.form(),

                layer = layui.layer;


                $('.x-login-right li').click(function(event) {

                    color = $(this).attr('color');

                    $('body').css('background-color', color);

                });


/*监听提交

                form.on('submit(save)',

                function(data) {

                    console.log(data);

                    layer.alert(JSON.stringify(data.field), {

                      title: '最终的提交信息'

                    },function  () {

                        location.href = "__STATIC__/index.html";

                    })

                    return false;

                });

*/

            });

        </script>

<script>

    $(function(){

  $("#loginbt").on('click',function(){

      $.ajax({

      type:'POST',

  url:"{:url('login/check')}",

  data:$(".layue-form").serialize(),

  dataType:"json",

  success:function(data){

      if(data.status==1){

      alert(data.message);

  window.loction.href="{:url('index/index')}";

  }else{

      alert(data.message);

  window.loction.href="{:url('login/index')}";

  }

  }

  })

  })

})

</script>


    </body>


</html>

PhpNewerPhpNewer2599 days ago1630

reply all(3)I'll reply

  • phpcn_u10955

    phpcn_u109552017-11-03 11:37:19

    You have too much code, I didn’t look carefully. You can use the developer tools to print logs to find errors. Also, I see that you used the layer pop-up layer, but you did not use the pop-up layer module

    reply
    0
  • PhpNewer

    PhpNewer2017-11-01 14:37:12

    This is the backend login controller code:

    <?php

    namespace app\admin\controller;

    use app\admin\common\Base; //Base has automatically referenced various think internal library files, there will be no mistakes here

    use app\admin\model\Admin;

    class Login extends Base{

    /**Render login interface*/

    public function index() {

    return $this->fetch('login');

    }

    /**Verify user identity*/

    public function check(Request $request){

    //Set status

    $status=0;

    //Get the data submitted by the form and save it in the variable

    $data=$request->param();

    $name =$data['name'];

    $password=md5($data['password']);

    //Query in the admin table

    $map=['name'=>$name];

    $admin = Admin::get($map); //Returns an object

    //Verify username and password separately

    //If the user is not found

    if(is_null($admin)){

    / /Set return information

    $message = 'Username is incorrect';

    }elseif($admin-> password != $password){

    $message= 'Password is incorrect';

    }else{

    //If the username and password are correct, it means it is a legitimate user

    $status=1;

    $message='Verification passed, please click OK to enter the background';

    //Update the number of logins and login time in the table

    $admin->setInc('login_count');/ /tp5 auto-increment method

    $admin->save(['lasttime'=>time()]);

    //Save user login information into session for use Other controllers perform login judgment

    Session::set('user_id',$name);

    Session::set('user_info',$data);

    }

    return ['status'=>$status,'message'=>$message];

    }


    /**

    * sign out

    */

    public function loginout()

    {

    //Delete the current user’s login information

    Session::delete ('user_id');

    Session::delete('user_info');

    //Execution is successful and returns to the login interface

    $this->success('Logout successful, returning','login/index');

    }

    }

    reply
    0
  • PhpNewer

    PhpNewer2017-11-01 14:33:57

    This background front-end is the introduced X-ADMIN framework

    reply
    0
  • Cancelreply