我有一种情况,我需要从ajax调用中获取值,然后将该值传递给回调函数。就像这样:传递输出作为回调的输入参数
function getValue(callback){
var val = getfromajax();
//need to return value and then execute the callback here
return val;
callback();
}
var myval = getValue(function(){
alert(myvalue)
})
在上面的例子中functon showValue我需要调用的getValue和使用返回的值,并把它传递给回调函数(它提醒它)。
有没有办法做到这一点?
getfromajax()*异步*顾名思义? – David
是的,实际上它是ajax()函数。 – Lamar
您最好阅读:[如何从异步调用返回响应?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call )。 'getfromajax()''' – charlietfl