Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在以下 jQuery 示例中正确返回对象:-
function get_stockists() { $.getJSON("/stockists/ajax_get_all", function(data) { //console.log(data); }); } var stockists = get_stockists(); console.log(stockists);
最好的方法不是返回,而是使用回调函数:
function getStockists(callback) { $.getJSON("/stockists/ajax_get_all", callback); } getStockists(function(stockists) { console.log(stockists); });