The Problem
I am trying to return the result of jQuery's getJSON
method.
What I've Tried
I under stand that the getJSON method is asynchronous, and that I cannot simply return the result as you can with synchronous code.
I've looked at other posts and I tried messing around with promises, as well as callbacks, etc... but have gotten nowhere.
My Code (Before Trying Promises, Callbacks, Etc...)
function getCart() {
jQuery.getJSON("/cart.js").done(function (cart) {
return cart;
});
}
cart = getCart();
console.log(cart);
Any direction would be greatly appreciated!