<body>
<p>username:<input class="username" value="<?= $username?>"></p>
<p>password:<input type="password" class="password"></p>
<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
<p><input type="button" class="sub" value="提交"></p>
</body>
</html>
<script>
$('.sub').on('click',function () {
var json = {};
json.username = $('.username').val();
json.password = $('.password').val();
json._csrf = $('#_csrf').val();
$.ajax({
url:'/?r=site/ruquest',//或者 '/admin/user/request'
type:'POST',
data:json,
dataType:'json',
success:function (response) {
console.log(response);
}
})
})
</script>
后台接收
$request = Yii::$app->request;
$get = $request->get();
$post = $request->post();
$params = $request->bodyParams;//获取全部参数
globals::outputJson(0,'','',$post);
布局
image.png
image.png
image.png
网友评论