Подключить json
Привет!
Подскажите как подключить Json в Script.
Идея такая что есть список ul, и через Script я создаю нужное количество li, которое определяется количеством элементов массива из Json. Праметры присваиваются также из этого Json`a.
************************************************** **********
// json файл
var product = {
product: [
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/1.jpg",
title : "Tissot",
text : "Aghunny watch from the company Tissot"
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/2.jpg",
title : "Rolex",
text : "One of the most famous models in the world."
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/3.jpg",
title : "Cartier",
text : "Cartier products were exhibited at the World."
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/4.jpg",
title : "Omega",
text : "The official chronometers of the US Army."
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/5.jpg",
title : "Patek Philippe",
text : "One of the most expensive serial watches in the world."
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/6.png",
title : "Swatch",
text : "Swatch (second hours) - a watch for each day."
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/7.jpg",
title : "Breguet",
text : "A brand with more than 200 years of history."
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/8.jpg",
title : "TAG Heuer",
text : "The world's largest luxury holding company"
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/9.jpg",
title : "Longines",
text : "Longines was the first to launch a wristwatch"
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/10.jpg",
title : "Chopard",
text : "Precise pocket watches and chronometers"
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/11.png",
title : "Calvin Klein",
text : "Watches are among the best in the world"
},
{
href : "https://secunda.com.ua/shop/chasy-naruchnye/men.html",
image : "images/product/watch/12.png",
title : "Seiko",
text : "Seikosha means "House of Exquisite Craftsmanship"."
},
]
}
$(document).ready(function(){
var productJSON = JSON.stringify(product);
//************************************************** ************************************************** **********
var allproducts = JSON.parse(productJSON);
var productsLength = allproducts.product.length;
for(var i=0; i<productsLength; i++){
document.getElementById('listbox').innerHTML += '<li class="content__box_item"><div class="content__box_conteiner"><a href="' + allproducts.product[i].href + '"><div class="content__box_imag"><img src="' + allproducts.product[i].image + '"></div><h2 class="box_article_title">' + allproducts.product[i].title + '</h2><p class="box_article_text">' + allproducts.product[i].text + '</p></a></div></li>';
}
});
************************************************** *******
Я хочу Json хранить отдельно, но не получается это реализовать.
Если не трудно подскажите способ:
- хранения на сервере
- хранение в в папке с проектом (допустим js)
|