【问题标题】:Yii2 403 forbidden during ajax callYii2 403在ajax调用期间被禁止
【发布时间】:2020-08-29 06:37:29
【问题描述】:

我在order/my-cart 中有jquery,我试图从order/delivery-verify 获取数据。我的javascript如下

$('form#Confirm').submit(function(event){
        event.stopPropagation();
        event.preventDefault();

        Core.ajax({
                type: "GET",
                dataType: "json",
                url: "/order/delivery-verify",
                data: $(this).serialize(),
                success: function (result) {
                    if (typeof (result.status) != 'undefined') {
                        if (result.status == 200) {
                            window.location.href = '/order/checkout';
                        } else {
                            Core.handleInvalidServerResponse(result);
                        }
                    }
                }
            });
    })

此脚本在 subdomain.example.com 中运行良好,但在另一台服务器 subdomain.example-one.com 中引发 403 错误

编辑 OrderController.php

<?php
namespace frontend\controllers;

use common\components\CErrorAction;
use common\helpers\Com;
use frontend\components\CController;
use frontend\models\User;
use yii;
use frontend\models\Configuration;
use yii\helpers\Json;
use yii\helpers\ArrayHelper;
use frontend\models\Order;
use common\helpers\Mailer;

use frontend\models\NewsletterSubscriber;
/**
 * Class SiteController
 * @package frontend\controllers
 */
class OrderController extends CController
{

    /**
     * @return array
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => CErrorAction::class
            ],
        ];
    }

   /**
     *
     * @return type Json
     * @Title("Checkout verify")
     */
    public function actionDeliveryVerify()
    {
    .....
    }
......
}

【问题讨论】:

  • 检查第二台服务器上该特定路径的权限。确保可以访问控制器操作 delivery-verify
  • @HarishST 我无法从 OrderController 上的任何操作中得到响应
  • 你的控制器中有behaviors() 方法吗?
  • @HarishST OrderController 中没有行为方法

标签: php ajax controller yii2 http-status-code-403


【解决方案1】:

public function accessRules()
{
    return array(
        array(
          'allow',
          'actions'=>array('delivery-verify'),
          'users'=>array('*'),
        )
    );
}

尝试在您的控制器中添加accessRules()。以上代码允许任何用户访问delivery-verify 操作。

Yii1.1官方API文档请点击以下链接: - Yii1.1 CController - Yii1.1 CAccessControlFilter - Authentication and Authorization

【讨论】:

  • 同样的错误 403 禁止。我很困惑它在一台服务器上工作,而不是在另一台服务器上工作。
  • 可能是检查文件的权限。
  • 0644 是权限
  • 其他控制器文件权限呢?尝试更改权限并检查是否有效。
  • 所有文件都是0644。OK会更改并检查。
猜你喜欢
  • 2014-04-13
  • 2012-10-13
  • 2012-12-24
  • 2021-06-17
  • 1970-01-01
  • 2017-05-16
  • 1970-01-01
  • 1970-01-01
  • 2019-04-10
相关资源
最近更新 更多