search

Home  >  Q&A  >  body text

Hello teacher, I wrote the code according to your course. The front-end data cannot be submitted to the database, and there are no pop-up prompts. Please correct me.

//regiser

<!-头部->{include file="public:header"/}<!-导航->{include file="public:nav"/}<div class="col-md-8">    <div class="page-header text-center">        <h2>用户注册</h2>    </div>    <form class="form-horizontal" method='post' id="login">    <div class="form-group">            <label for="inputEmail1" class="col-sm-2 control-label">用户:</label>            <div class="col-sm-10">                <input type="text" name="name" class="form-control" id="inputEmail1" placeholder="username">            </div>        </div>        <div class="form-group">            <label for="inputEmail2" class="col-sm-2 control-label">邮箱:</label>            <div class="col-sm-10">                <input type="text" name="email" class="form-control" id="inputEmail2" placeholder="Email">            </div>        </div>        <div class="form-group">            <label for="inputEmail3" class="col-sm-2 control-label">手机:</label>            <div class="col-sm-10">                <input type="text" name="mobile" class="form-control" id="inputEmail3" placeholder="Mobile">            </div>        </div>        <div class="form-group">            <label for="inputEmail4" class="col-sm-2 control-label">密码:</label>            <div class="col-sm-10">                <input type="password" name="password" class="form-control" id="inputEmail4" placeholder="Password">            </div>        </div>        <div class="form-group">            <label for="inputEmail5" class="col-sm-2 control-label">确认密码:</label>            <div class="col-sm-10">                <input type="password"   name="password_confirm"  class="form-control" id="inputEmail5" placeholder="Password_confirm">            </div>        </div>        <div class="form-group">            <div class="col-sm-offset-2 col-sm-10">                <button type="submit" class="btn btn-default" id="register">注册</button>            </div>        </div>    </form></div><script>    $(function () {        $("#register").on('click',function () {           alert($('#login').serialize());            $.ajax({                type:'post',                url:"{:url('index/user/insert')}",                data:$('#login').serialize(),                dataType:'json',                success:function (data) {                   alert('成功了')                }            })        })    })</script>{include file="public:rigt"/}{include file="public:footer"/}

//User

<?php/** * registration page */namespace app\index\controller;use app\common\controller\Base;use app\common\model\User as UserModel;use think\facade\Request;class User extends Base{    public function register()    {        $this ->assign('title','用户注册');        return $this ->fetch();    }    public function insert()    {        if ( Request ::isAjax()){          $data =  Request::except('password_confirm','post');           if(UserModel::create($data)) {               return ['status'=> 1, 'message'=> '注册成功'];            }else{               return ['status'=> 0, 'message'=> '注册失败'];           }        }else{          $this -> error("请求类型错误",'register');        }    }}

AndyAndy1318 days ago1061

reply all(1)I'll reply

  • 查无此人

    查无此人2021-04-07 11:37:29

    Your code is too messy, and there is no TP version you downloaded. You can package the entire project and send it to me.

    The current version of thinkphp is already 6. You can learn version 6.

    According to your question, if the PHP operation is not completed and an error is reported, there will definitely be no pop-up box in the JS code.

    Check the php code first to see if there are any errors. F12 of the browser can be viewed.

    reply
    0
  • Cancelreply