-1

I facing and issue Access to XMLHttpRequest at 'http://demo.equalinfotech.com/Iadiva/images/product/1634623781ladiva_barbara_01.glb' from origin 'http://localhost:8100' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I build a app on IONIC on that app I want to display 3D images and for 3D images I am using .glb format I am using backend as php, I am sending URL through API.

I am going to mention my code below

public function 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 "You have 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();

}

}

enter image description here

enesh pal
  • 39
  • 9
  • Does this answer your question? [Angular - JSON Put and Delete Returns 403 (But postman app works well)](https://stackoverflow.com/questions/54168106/angular-json-put-and-delete-returns-403-but-postman-app-works-well) – Raphaël Balet Oct 20 '21 at 11:10
  • Not sure how your Postman screenshot is relevant to this? Only cross-domain AJAX requests in browsers are subject to [CORS restrictions](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). A paste of your AJAX code, and some Info from your browser's network tool would be a lot more useful. – ADyson Oct 20 '21 at 12:06

1 Answers1

0

Make sure the domain name from which you're requesting data is present in network_security_config.xml file.

mahen23
  • 720
  • 2
  • 11
  • 24