-2
我发现这个问题几乎完全一样:Return value from nested function in Javascript
问题是函数传递给jQuery的$.ajax
函数。下面是我有:
function doSomething() {
// Do some stuff here
console.log(getCartInfo());
}
function getCartInfo() {
var url = blog_location + '?reqCartData=1';
$.ajax({
url: url,
type: 'get',
success: function(data) {
return data; <------------- This
}
});
}
我需要返回data
到DoSomething的功能,如果是有道理的。我试图返回整个$.ajax
函数,但返回整个对象。有任何想法吗?
这要求每天的基础上。请参阅[如何从函数返回AJAX调用的响应?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call-from-a功能) – 2013-03-08 12:16:12
@FabrícioMatté你是对的,对不起。 *编辑:*投票结束! – qwerty 2013-03-08 12:24:15