Skip to content

Instantly share code, notes, and snippets.

@Llewellynvdm
Last active July 22, 2023 11:15
Show Gist options
  • Save Llewellynvdm/2cb417995d11ba695565aca52c54bff1 to your computer and use it in GitHub Desktop.
Save Llewellynvdm/2cb417995d11ba695565aca52c54bff1 to your computer and use it in GitHub Desktop.
Here is a jQuery script to make an API call from your own application
jQuery.ajax({
url:'https://archived.getbible.net/json',
dataType: 'jsonp',
data: 'p=John1&v=kjv',
jsonp: 'getbible',
success:function(json){
// set text direction
if (json.direction == 'RTL'){
var direction = 'rtl';
} else {
var direction = 'ltr';
}
// check response type
if (json.type == 'verse'){
var output = '';
jQuery.each(json.book, function(index, value) {
output += '<center><b>'+value.book_name+' '+value.chapter_nr+'</b></center><br/><p class="'+direction+'">';
jQuery.each(value.chapter, function(index, value) {
output += ' <small class="ltr">' +value.verse_nr+ '</small> ';
output += value.verse;
output += '<br/>';
});
output += '</p>';
});
jQuery('#scripture').html(output); // <---- this is the div id we update
} else if (json.type == 'chapter'){
var output = '<center><b>'+json.book_name+' '+json.chapter_nr+'</b></center><br/><p class="'+direction+'">';
jQuery.each(json.chapter, function(index, value) {
output += ' <small class="ltr">' +value.verse_nr+ '</small> ';
output += value.verse;
output += '<br/>';
});
output += '</p>';
jQuery('#scripture').html(output); // <---- this is the div id we update
} else if (json.type == 'book'){
var output = '';
jQuery.each(json.book, function(index, value) {
output += '<center><b>'+json.book_name+' '+value.chapter_nr+'</b></center><br/><p class="'+direction+'">';
jQuery.each(value.chapter, function(index, value) {
output += ' <small class="ltr">' +value.verse_nr+ '</small> ';
output += value.verse;
output += '<br/>';
});
output += '</p>';
});
if(addTo){
jQuery('#scripture').html(output); // <---- this is the div id we update
}
}
},
error:function(){
jQuery('#scripture').html('<h2>No scripture was returned, please try again!</h2>'); // <---- this is the div id we update
},
});
@timaday
Copy link

timaday commented Oct 12, 2021

how is the addTo variable set?

@Llewellynvdm
Copy link
Author

This API has been abandoned... please look at the new API v2

I have written a BASH random scripture generator, and a easy way to get a chapter also with BASH, I am sure you can convert that to JavaScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment