Assuming that the p5js library functions properly, you should refrain from using document.write
in your code. Instead, locate where you would like the data to appear on your webpage and insert it into that specific element using its unique id
.
For instance, suppose you want to display a quote within a paragraph:
<p id="quote">Alternate Text</p>
To achieve this, replace any instances of document.write
with the following snippet:
document.getElementById("quote").innerHTML = data;
Incorporating all these elements, your JavaScript code may resemble the following:
function setup() {
loadJSON('http://labs.bible.org/api/?passage=votd&type=json', gotData, 'jsonp');
}
function gotData(data){
document.getElementById("quote").innerHTML = data;
// note: var bibleVerse is never used
}
The text "Alternate Text" serves as a fallback in case the JavaScript functions encounter errors.
For those new to web development: if you opt not to utilize jQuery's $(document).ready()
function, ensure that the JavaScript script is placed inside the <body>
tag towards the bottom. This arrangement ensures that the page content loads first before executing the JavaScript code.