i write this question because i have this site i need to make, and my only problem is the JSON. i have this url with the JSON but when ever i try to work with the link it gives me an error, that you can see further down in my question, but when take all the data from the url i put it in a VAR then i will get no error and i will see me data, but that is not what is supposed to happen.
i got this problem with my JSON, some how i cant see my data on my HTML page, and i cant find the problem.
here you have my HTML page:
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="js/jquery-3,2,1.js" type="text/javascript"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<table id="product_table" class="table table-responsive table-sm">
<thead>
<tr>
<th>Product</th>
<th>Photo</th>
<th>Sizes</th>
<th>Price</th>
<th>Old Price</th>
<th>Delivery</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script src="js/bootstrap.js"></script>
<script src="js/npm.js"></script>
</div>
</body>
</html>
and here you have my 2 scripts i tried out the first one i try to get the JSON from an url the second one i downloaded the JSON locally down on my pc
<!-- <script>
var productJSON = "https://www.unisport.dk/api/sample/";
$.getJSON(productJSON, function(data) {
$.each(data.products, function(i,f){
var tblRow ="<tr>" + "<td>" + f.name + "</td>" + "<td>" + "<img class='img-responsive' alt='photo of product' src='" + f.image + "'>" + "</td>" + "<td>" + f.sizes + "</td>" + "<td>" + f.price + " " + f.currency + "</td>" + "<td>" + "<s>" + f.price_old + " " + f.currency + "</s>" + "</td>" + "<td>" + f.delivery + "</td>" + "</tr>"
$(tblRow).appendTo("#products tbody");
});
});
</script> -->
<script>
$(document).ready(function(){
$.getJSON("unisport.json", function(data){
var product_data = '';
$.each(data, function(key, value){
product_data += '<tr>';
product_data += '<td>'+value.name+'</td>';
product_data += '<td><img scr="'+value.image+'"></td>';
product_data += '<td>'+value.sizes+'</td>';
product_data += '<td>'+value.price+' '+value.currency+'</td>';
product_data += '<td>'+value.price_old+' '+value.currency+'</td>';
product_data += '</tr>';
});
$('#product_table').append(product_data);
});
});
</script>
how the data has been setup: all the JSON data is from this url: https://www.unisport.dk/api/sample/
{"is_customizable": "0",
"delivery": "1-2 dage",
"kids": "0",
"name": "adidas Tr\u00e6ningsbukser Z.N.E. Road Trip - Gr\u00e5",
"sizes": "XX-Large",
"kid_adult": "0",
"free_porto": "0",
"image": "https://d2ij1pxeion66i.cloudfront.net/product/157128/010c01d20cac.jpg",
"package": "0",
"price": "399,00",
"url": "https://www.unisport.dk/fodboldudstyr/adidas-trningsbukser-zne-road-trip-gra/157128/",
"online": "1",
"price_old": "799,00",
"currency": "DKK",
"img_url": "https://s3-eu-west-1.amazonaws.com/product-img/157128_maxi_0.jpg",
"id": "157128",
"women": "0"},
This is my error message in my console:XMLHttpRequest cannot load
Now my question is how does i fix the problem if there is one or what does i miss, in order to get it working, also i would really like to get the Data trough the URL as shown in the first script
(also i only use jQuery, Bootstrap and HTML in this project.)
EDIT Problem fixed, since i'm doing this project locally on my PC i had to start up a local server, that i forgot all about. So if any one else have some problems as me BE SURE TO DOUBLE CHECK that you have a local server running for the project