Maison > Questions et réponses > le corps du texte
<?php
/**
* Créé par PhpStorm.
* Utilisateur : Administrateur
* Date : 2018-4-3
* Heure : 15:23
*/
namespace appindexcontroller;
utilisez appcommoncontrollerBase;
utilisez appcommonmodelTest comme TestModel;
class Test extends Base
{
Fonction publique test1()
{
return $ This-& gt; fetch ();
}
public function insert () {
if (request :: isajax ()) {
$ data = request :: password_confirm ',' post ' ); en utilisant if (TestModel::create ($data)){
use 's ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ return ['status'=>1, 'message'=>'Félicitations, l'inscription est réussie ! ']; E} else {
Retour [' Statut' = & GT; 'Message' = & GT; '];
}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title> Titre</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">Mot de passe</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">Mot de passe</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">Connexion</button>
</div>
</div>
</form>
<script>
$(function () {
$("#testButton").on('click',function () {
$.ajax({
type:'post',
url:"{:url('insert')}",
data: $ ('#testPost').serialize(),
dataType: 'json',
success: function (data) {
alert('成功了');
}
})
})
})
</script>
</body>
</html>
豆芽2018-04-09 20:52:15
Ajoutez use thinkRequest en haut
De plus, la méthode insert() doit passer des paramètres, insert(Requset $request)
{
$data = $request->param();
}