i have js code like this
var data = {
"items": [
{
"src": "xxx",
"url": "xxx",
"ttl": "xxx%"
},
]};
$.each(data.items, function(i, f) {
$('ul').append('<li class="scroll-nav"><a href="' + f.url + '"><img class="squareBig" src="' + f.src + '" download="' + f.ttl + '"></img></a></li>');
});
its work perfectly but i want replace var data ={xxx} with import url from github
i have try this code but not work 🙂
$.getJSON('https://raw.githubusercontent.com/user/lokal.json', data.items, function(i, f) {
$('ul').append('<li class="scroll-nav"><a href="' + f.url + '"><img class="squareBig" src="' + f.src + '" download="' + f.ttl + '"></img></a></li>');
});
and this is my json
var data = {
"items": [
{
"src": "https://xxx",
"url": "https://xxx",
"ttl": "METRO TV"
}
]};
plzz help me
2
Answers
You are using
.getJSON
incorrectly..getJSON
will returndata
and you need to use that data to loop over and process.Check this out: .getJSON
Following code should work for you:
this is for you reference. you need to loop through items from your json data.
Demo https://jsbin.com/nicacux/edit?html,js,console,output
HTML
JS