views:

86

answers:

2

I'm trying to use this api that lets you reference an exact text, but the getJson does not seem to be working, it's just returning null.

$.getJSON('http://api.biblia.com/v1/bible/content/KJV.json?key=MYAPIKEY=John+3:16-18&style=bibleTextOnly', function(data) {
  alert(data);
});

I just took the key out, i've been testing it with my real api key, and it works fine when i just visit the url. is there anything else i need to do to make it work?

This is what you get from the url when you have an api key in the url:

{"text":"For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. For God sent not his Son into the world to condemn the world; but that the world through him might be saved. He that believeth on him is not condemned: but he that believeth not is condemned already, because he hath not believed in the name of the only begotten Son of God."}

+1  A: 

Try this out instead, just for testing:

$.ajax({
  url: 'http://api.biblia.com/v1/bible/content/KJV.json?key=MYAPIKEY=John+3:16-18&style=bibleTextOnly',
  dataType: 'json',
  success: function(data) { alert(data); }
});

Does that work for you?

Matt Dawdy
+1  A: 

key=MYAPIKEY=John+3:16-18

Is the parameter value already URL-encoded? Look like not. The =, + and : are reserved characters in an URL.

Try this instead:

key=MYAPIKEY%3DJohn%2B3%3A16-18

To do this yourself in JS, pass MYAPIKEY=John+3:16-18 through encodeURIComponent() and use its return value in the query string.

BalusC