I'm getting data from server using JQuery and JSON. I defined getBooksDoneFunc
as variable because I need to be able to call this function not only once (when getBooks
is done) . Unfortunately, I cannot call getBooksDoneFunc
from inside of signInOK
as window["getBooksDoneFunc"]();
. Why? What is the best way to call this function?
function getBooks(){ return $.getJSON( "bookstore.json" ); }
var getBooksDoneFunc = function(json) {
$.each(json.books, function(i, json){ .......... });
}
getBooks().done(getBooksDoneFunc);
function signInOK(){
window["getBooksDoneFunc"]();
}
PS. The idea for window["getBooksDoneFunc"]();
was taken from SO answer
UPDATE:
var booksJSON = {};
window["getBooksDoneFunc"](booksJSON);
getBooksDoneFunc
must be called with parameters nevertheless the call to getBooksDoneFunc
fails. signInOK
is defined outside of $(document).ready(function(){ });
but called inside of it.