Last active
July 22, 2023 11:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}, | |
}); |
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
how is the addTo variable set?