【问题标题】:Facing CORS policy issue面临 CORS 政策问题
【发布时间】:2021-12-07 04:45:12
【问题描述】:

我在 'http://demo.equalinfotech.com/Iadiva/images/product/1634623781ladiva_barbara_01.glb' 面临并发出访问 XMLHttpRequest 来自来源'http://localhost:8100' 的问题已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。

我在 IONIC 上构建了一个应用程序,我想在该应用程序上显示 3D 图像,对于 3D 图像,我使用 .glb 格式,我使用后端作为 php,我通过 API 发送 URL。

我将在下面提及我的代码

公共函数 getProductDetails() {

    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Headers: *");
    header("Content-Type: application/json");
    header("Access-Control-Expose-Headers: Content-Length, X-JSON");
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

// echo "你有 CORS!";

    $json_file = file_get_contents('php://input');

    $jsonvalue = json_decode($json_file, true);



    $category_id = $jsonvalue['category_id'];

    $product_id = $jsonvalue['product_id'];

    

    $APPPATH=APPPATH;

    $APPPATHArr=explode('application',$APPPATH);

    $glbURL=$APPPATHArr[0];



    $response = $this->customer->getProductDetailsNew($category_id, $product_id);



    if (!empty($response)) {

        $results['success'] = 'true';

        $results['error'] = 0;

        $results['data'] = $response;

        $results['msg'] = 'Fetched successfully';

        $results['service'] = BASE_URL . 'api/customers/getCategory';

    } else {

        $results['success'] = 'false';

        $results['error'] = 1;

        $results['data'] = [];

        $results['msg'] = 'Record Not Found';

        $results['service'] = BASE_URL . 'api/customers/getCategory';

    }

    echo json_encode($results);

    exit();

}

}

【问题讨论】:

标签: javascript php angular codeigniter ionic-framework


【解决方案1】:

确保您从中请求数据的域名存在于network_security_config.xml 文件中。

【讨论】:

    猜你喜欢
    • 2020-12-23
    • 2020-01-15
    • 2021-06-24
    • 1970-01-01
    • 2020-07-28
    • 2022-01-20
    • 2020-03-30
    • 1970-01-01
    • 2017-10-05
    相关资源
    最近更新 更多