yii2:doajax(post)会报500错误 (个人项目代码奉上,希望对大家有帮助, 下面是执行一个删除操作)

jquery代码 

<script>
    $(function () {

        $(".del").click(function () {
            var id=$(this).attr("name");
            $("input[name='del_id']").val(id);
        });

        $("#delete").click(function () {

            var id=$("input[name='del_id']").val();
            $.post('<?=U('product/delete')?>',{id:id},function (rs) {
                if (rs.status==1){
                    $('#Modal-delete').modal('hide');
                    layer.msg(rs.info);
                    location.reload();
                }
            },"json")

        });
//        $("#example1").DataTable();
    })
</script>
controller代码   关闭csrf

public function beforeAction($action) {
    $currentAction = $action->id;
    $currentActions = ['article_delete'];

    if(in_array($currentAction,$currentActions)) {
        $action->controller->enableCsrfValidation = false;
    }
    parent::beforeAction($action);
    return true;
}

/**
 * 直播表的删除 把为1的status改为0
 * @auth magang
 * @time 2017/5/26 18:18
 */
public function actionArticle_delete(){
    $id = Th::request()->post();
    if(!empty($id)){
        $User = Broadcast::findOne($id);
        $User->status = '0';
        if($User->save()){
            $this->info("删除成功!",1);
        }
    }else{
        $this->info("无法获取数据!",0);
    }
}


猜你喜欢

转载自blog.csdn.net/qq_35458793/article/details/72781387