【发布时间】: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();
}
}
【问题讨论】:
-
不确定您的 Postman 屏幕截图与此有何关联?只有浏览器中的跨域 AJAX 请求受CORS restrictions 约束。粘贴您的 AJAX 代码以及浏览器网络工具中的一些信息会更有用。
标签: javascript php angular codeigniter ionic-framework