BigCommerce API - PHP AJAX on Cart for Weight Returns
<p>I'm trying to return product weights so they display on the cart for my customers.</p>

<p>In the cart template, I'm calling this external JS file from the cart template in BigCommerce </p>

<p>storefront: <code>https://store-xxx.mybigcommerce.com/cart.php</code> or backend template: <code>cart.html</code></p>

<pre><code>$(document).ready(function () {

var url = 'http://xxxx.com/cartProduct.php';
var prodWeights;    


 $(".prod_SKU").each(function () {

    $.ajax({
        url: url, 
        method: 'POST',
        dataType: "json",
        data: {sku: $(this).text()},
        contentType: "application/json; charset=utf-8",
        async: false,
        crossDomain: true,

        success: function (result) {
             prodWeights = result;
        },
        error: function (request, textStatus, errorThrown) {
            console.log(request.responseText);
            console.log(textStatus);
            console.log(errorThrown);
        }
    });    
});



 console.log(prodWeights);


 });
</code></pre>

<p>So it passes the SKU properly to the PHP file, "cartProduct.php":</p>

<pre><code>&lt;?php

 $sku = $_POST['sku'];

 $api_url = 'https://store-xxxxxx.mybigcommerce.com/api/v2/products?sku=' . sku;
 $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url ); 
 curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content-Length: 0') );                                   
 curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET'); 
 curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); 
 curl_setopt( $ch, CURLOPT_USERPWD, "xxxxx:xxxxxxxxxxxx" ); 
 curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );   
 $response = curl_exec( $ch );   
 $result = json_decode($response); 
 print_r($result);


 ?&gt;
</code></pre>

<p>I believe there might be an authorization issue, when I try to hit my PHP as just "http://", I get this error:
<a href="https://i.stack.imgur.com/1FbD7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1FbD7.png" alt="error1"></a></p>

<p>When I try "https://" I get this:
<a href="https://i.stack.imgur.com/nRgPS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nRgPS.png" alt="error 2"></a></p>