Here is what I have come up with this far: I am getting nothing in the console.log that I am trying to print; although no errors either. My goal is to handle an ajax request (multiple later) with vanilla javascript (ES6).
function loadJSON(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'https://www.website.com/wp-json/acf/v3/options/options', true); // Replace 'my_data' with the path to your file
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}
function init() {
loadJSON(function(response) {
// Parse JSON string into object
var actual_JSON = JSON.parse(response);
console.log(response)
});
}
});
Here is what my website ../options...
file looks like:
{"acf":{"1yr_short_copy":"<p>Our 1 Year Money Back Guarantee either leaves you 100% satisfied,....
So, for instance - I just want to grab field 1yr_short_copy
text data and print into html div. I know this is incredibly easy with jQuery; but I am not able to use jQuery on current application - so am seeking a Vanilla ES6 technique.. Any thoughts?