老師,您好,我按照您的課程寫的代碼,前端的數(shù)據(jù)無(wú)法提交的數(shù)據(jù)庫(kù),同時(shí)也沒(méi)用彈窗提示。煩請(qǐng)指正。
問(wèn)題描述
//regiser
<!-頭部->{include file="public:header"/}<!-導(dǎo)航->{include file="public:nav"/}<div class="col-md-8"> <div class="page-header text-center"><h2>用戶注冊(cè)</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">手機(jī):</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">確認(rèn)密碼:</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">注冊(cè)</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/** * 注冊(cè)頁(yè)面 */namespace appindexcontroller;use appcommoncontrollerBase;use appcommonmodelUser as UserModel;use thinkfacadeRequest;class User extends Base{ public function register() {$this ->assign('title','用戶注冊(cè)');return $this ->fetch(); } public function insert() {if ( Request ::isAjax()){ $data = Request::except('password_confirm','post'); if(UserModel::create($data)) { return ['status'=> 1, 'message'=> '注冊(cè)成功']; }else{ return ['status'=> 0, 'message'=> '注冊(cè)失敗']; }}else{ $this -> error("請(qǐng)求類型錯(cuò)誤",'register');} }}
問(wèn)題解答
回答1:你這個(gè)代碼太亂了,也沒(méi)有你下載的tp版本。你可以把整個(gè)項(xiàng)目,打包發(fā)給我。
現(xiàn)在thinkphp的版本,已經(jīng)是6了。 可以學(xué)習(xí)6的版本。
按照你的問(wèn)題,php沒(méi)有操作完,報(bào)錯(cuò)了,js代碼,就肯定不會(huì)有彈框。
你先看下php代碼,是否有報(bào)錯(cuò)。 瀏覽器的F12,可以查看。
相關(guān)文章:
1. 老師,按tab鍵不起作用怎么回事2. 在cmd下進(jìn)入mysql數(shù)據(jù)庫(kù),可以輸入中文,但是查看表信息,不顯示中文,是怎么回事,怎新手,請(qǐng)老師3. 表單提交驗(yàn)證,沒(méi)反應(yīng),求老師指點(diǎn)4. 請(qǐng)老師發(fā)一下=TP6.0 搭建個(gè)人博客實(shí)戰(zhàn)(玉女心經(jīng)版)的數(shù)據(jù)庫(kù)!謝謝5. 韋小寶老師的TP基礎(chǔ)實(shí)戰(zhàn)教學(xué)6. 老師,怎么不講一次性添加多個(gè)數(shù)據(jù)7. 老師 請(qǐng)問(wèn)那個(gè)小尺子工具中文網(wǎng)有嘛8. 老師,項(xiàng)目導(dǎo)入后,只有左邊的欄目正常,右邊的內(nèi)容顯示No input file specified.,咋回事9. 為什么老師,你de button按鈕處可以有兩個(gè)ID是一樣的id="loginbtn" 而不會(huì)報(bào)錯(cuò)啊10. 老師,請(qǐng)問(wèn)下為什么這個(gè)地方的單引號(hào)里面的變量能夠被解析呢?

網(wǎng)公網(wǎng)安備