Heim > Fragen und Antworten > Hauptteil
<?php
/**
* Erstellt von PhpStorm.
* Benutzer: Administrator
* Datum: 3.4.2018
* Zeit: 15:23
*/
namespace appindexcontroller;
use appcommoncontrollerBase;
use appcommonmodelTest as TestModel;
class Test erweitert Base
{
Öffentliche Funktion test1()
{
return $ this->fetch();
}
öffentliche Funktion insert()
{
zu mit if(TestModel::create($data)) {
use 's ' ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ return ['status'=>1, 'message'=>'Herzlichen Glückwunsch, die Registrierung war erfolgreich! ']; E} else {
Return ['Status' = & GT; '];
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Title</title>
<link rel="stylesheet" href=" /static/css/bootstrap.css"/>
<script src="/static/js/jquery-3.3.1.min.js "></script>
<script src="/static /js/bootstrap.js"></script>
<body>
<div class="form-group">
" " <label for="inputEmail3" class="col-sm-2 control- label">Email</label>
" " <div class="col-sm -10">
;
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col -sm-10">
<input type="password" name="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</ div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class=" col-sm-10">
<input type="password" name="password_confirm" class="form-control" id="inputPassword4" 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="testButton">Anmelden</button>
</div>
</div>
</form>
<script>
$(function () {
$("#testButton").on('click',function () {
$.ajax({
type:'post',
url:"{:url('insert')}",
Daten: $ ('#testPost').serialize(),
dataType: 'json',
success: function (data) {
alert('成功了');
}
})
})
})
</script>
</body>
</html>
豆芽2018-04-09 20:52:15
最上面添加use think\Request
另外 insert()这个方法里面需要传入参数,insert(Requset $request)
{
$data = $request->param();
}