I've put together a system to parse JSON and render it with some simple CSS. Though, I've done this using a variable. I don't want to output the data within the script. Instead, gather it from a local or remote URL.
<script type='text/javascript'>
$(window).load(function(){
var data={"users":[
{
"title":"Dieter Rams Video",
"content":"Only text will go here. Limited to 100 characters per panel.",
"url":"http://website.me/video.php?=89697976996",
},
{
"title":"IoT Ecosystem",
"content":"Villalobos",
"url":"http://google.com",
},
{
"title":"IoT Ecosystem",
"content":"Villalobos",
"url":"http://google.com",
},
{
"title":"IoT Ecosystem",
"content":"Villalobos",
"url":"http://google.com",
},
{
"title":"IoT Ecosystem",
"content":"Villalobos",
"url":"http://google.com",
},
{
"title":"IoT Ecosystem",
"content":"Villalobos",
"url":"http://google.com",
},
{
"title":"IoT Ecosystem",
"content":"Villalobos",
"url":"http://google.com",
}
]}
$(data.users).each(function() {
var output = "<a href='" + this.url + "'><div class='col-sm-12'><div class='panel panel-default'><div class='panel-body'><h4>" + this.title + "</h4><p>" + this.content + "</p></div></div></div></a>";
$('#feed').append(output);
});
});
</script>
How could I gather the JSON data from a URL source and output it like I am now?
Update
<script type='text/javascript'>
var data;
$.ajax({
dataType: "json",
url: `file://${__dirname}/data.json`,
data: data,
success: function(data) {
data = data;
}
});
$(window).load(function(){
$(data).each(function() {
var output = "<a href='" + this.url + "'><div class='col-sm-12'><div class='panel panel-default'><div class='panel-body'><h4>" + this.title + "</h4><p>" + this.content + "</p></div></div></div></a>";
$('#feed').append(output);
});
});
</script>