且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Yii 2中发送AJAX发布请求后出现400错误请求

更新时间:2021-07-21 07:50:12

只需添加csrf即可:

Just add csrf like :

       <script>
         var myUrl = "<?php echo Url::to(['table/edit']); ?>";        
       </script>
       $.ajax({
            type : "POST",
            url : myUrl,
            data: {id: userID,_csrf:'<?=\Yii::$app->request->csrfToken?>'},
            success  : function(response) {
                alert("Table is editted");
            }
        });