yii2视图渲染和前端请求及后台响应

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zchqq/article/details/82842587
<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);

布局

猜你喜欢

转载自blog.csdn.net/zchqq/article/details/82842587
今日推荐