Despite my best efforts, I have managed to navigate my way through the code thus far, but I am puzzled as to why the JSON data is not being sent to the HTML via JavaScript. I can manually input the necessary parts in the developer console after onLoad and it works fine... However, when running the script on its own to automatically populate the empty divs on the page - nothing happens... I understand that it's likely a small oversight on my part, but I'm ready to move on from this frustrating aspect of the site. Any assistance would be greatly appreciated.
/* General Info */
/* Data Routing Structure: */
/* (JSON DATA) (jsVariable) (cssID) */
/* title rTitle rTitle */
/* quote rQuote rQuote */
/* source rSource rSource */
/* text rText rText */
/*---------------------------------------*/
/* All JSON Data Files Are Located In */
/* (Root)/dta, And Are Split Into 12 */
/* Files.
/* Define Global Variables To Help */
/* Specify The Current Day And Month */
var date = new Date();
var m = date.getMonth();
var d = date.getDate();
var months = new Array()
months[0] = "january";
months[1] = "february";
months[2] = "march";
months[3] = "april";
months[4] = "may";
months[5] = "june";
months[6] = "july";
months[7] = "august";
months[8] = "september";
months[9] = "october";
months[10] = "november";
months[11] = "december";
var month = months[date.getMonth()];
/* Make The Connection To The JSON File */
var drOb;
var xhr = new XMLHttpRequest();
xhr.open('GET', "./dta/" + month +".json");
xhr.overrideMimeType("application/json");
xhr.setRequestHeader("Content-type", "application/json", true);
/* Pull JSON Data For Todays Date */
/* When The Page Loads, And Send To HTML */
xhr.onload = function()
{
if (this.readyState == 4 && this.status == 200)
{
var drOb = JSON.parse(this.response);
var rDate = m + d;
var rTitle = drOb[DAY][d].TITLE;
var rQuote = drOb[DAY][d].QUOTE;
var rSource = drOb[DAY][d].SOURCE;
var rText = drOb[DAY][d].TEXT;
document.getElementById("rDate").innerHTML = rDate;
document.getElementById("rTitle").innerHTML = xhr[DAY][D].TITLE;
document.getElementById("rQuote").innerHTML = rQuote;
document.getElementById("rSource").innerHTML = rSource;
document.getElementById("rText").innerHTML = rText;
}else{
alert("Daily Reflection is currently not available, please inform someone....");
}
};
xhr.send();