Home > OS >  Json parse url prestashop webservice
Json parse url prestashop webservice

Time:11-07

I ask you a question.

I need to parse a JSON coming from the Prestashop WebService.

At the moment I have saved all the JSON locally, in a file, I show it in a table and it works.

The code I'm using is this:

/// Read JSON
<script>
  $ ('# loan'). DataTable ({
       ajax: {
         url: 'products.json',
         dataSrc: 'products'
       },
       "columns": [
            {"data": "name"},
            {"data": "active"},
            {"data": "description"}
       ]
  });
</script>

My question is: How can I directly use the url (https://www.mywebsite.com/shop/api/products/?ws_key=ws_key?&output_format=JSON&display=full) instead of using the above method?

Thanks.

CodePudding user response:

I hope one of these helps:

Using cURL

$url = 'https://www.mywebsite.com/shop/api/products/?ws_key=ws_key?&output_format=JSON&display=full';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);

var_dump(json_decode($result, true));

Using AJAX

$.ajax({
    type:"GET", 
    url: "https://www.mywebsite.com/shop/api/products/?ws_key=ws_key?&output_format=JSON&display=full", 
    success: function(data) {
            console.warn(data);
        }, 
    error: function(jqXHR, textStatus, errorThrown) {
            alert(jqXHR.status);
        },
   dataType: "jsonp"
});​​​​​​​​​​​​​​​
  • Related