I started my hands on training on Jquery AJAX JSON this morning. I have knowledge of Jquery but JSON & Ajax is something new to me.
I have developed a small snippet of code to read JSON file with ajax and show the data values by appending the list.
using following div in body section.
<div id="tabPanelWrapper"></div>
Javascript:
$(document).ready(function() {
// Calling Ajax Function
loadContent();
});
function loadContent() {
$.ajax({
type: "GET",
url: "data.js",
dataType: "json",
cache: false,
contentType: "application/json",
success: function(data) {
alert("Success");
$.each(data.dashboard, function(i,post){
$('#tabPanelWrapper').append('<ul><li>' + data.id + '</li><li>' + data.name +'</li></ul>');
});
},
error: function(xhr, status, error) {
alert(xhr.status);
}
});
}
JSON File:
{
dashboard: [
{
"id": "tcm:20-1869",
"name": "FEATURED ARTICLE"
},
{
"id": "tcm:20-1869",
"name": "FEATURED ARTICLE"
}
]
}
Page is throwing 404 error. Please help me with this code.
Thanks in advance | Lokesh Yadav