Empty page when perform ajax query to api

Page 1 of 1 (2 items)
This post has 1 Reply | 1 Follower

Posts 1
Evgeny Tomenko | Forum Activity | Posted: Tue, Feb 22 2011 10:19 AM

When i perform request http://api.biblia.com/v1/bible/content/LEB.html.html?passage=John+1:1-3.16&key=[KEY]&style=fullyFormatted from browser i get correct text.

But when i perform same request from same computer but request performed as ajax query i get empty response page.

What could be wrong in this case. The key i use registered to the host i have installed

Posts 408
Bryan Smith | Forum Activity | Replied: Tue, Feb 22 2011 2:08 PM

Hi Evgeny,


Web browsers enforce the Same Origin Policy, which requires that all ajax requests go to the same domain that the document was loaded from. A script running on mysite.com can only make ajax calls to other pages on mysite.com, but cannot make requests to yoursite.com, api.biblia.com, or any other domain. 


The most common solution to this problem is to use JSONP, which is supported by the Biblia API. You will need to change the wrapping format to json, and add a callback parameter:



Here, "myCallback" is the name of a javascript function in the global scope that will be called with the result of the query. If you're using jQuery, you can simplify your code a lot by using their built-in JSONP support:



    url: http://api.biblia.com/v1/bible/content/LEB.html.json?passage=John+1:1-3.16&key=[KEY]&style=fullyFormatted,

    dataType: 'jsonp',

    success: function(data){





By setting the dataType property to 'jsonp', jQuery will generate the callback parameter for you and clean up after itself.


Let me know if you have any more questions.



Page 1 of 1 (2 items) | RSS