我对回调函数并没有完全理解,而且在最后关头遇到了一些困难。
在JS中,我调用一个函数,然后使用Dojo RPC Json Service调用PHP函数。我在Firebug中逐步跟踪这个函数,PHP正在执行,并通过回调返回给我正确的响应,但我不知道如何将值返回给最初调用JS函数的变量?例如:
JS Function 1
Function one(){
Var test = getPhp(number);
}
function getPhp(number)
{
this.serviceBroker = new dojo.rpc.JsonService(baseUrl + '/index/json-rpc/');
var result = serviceBroker.phpFunc(number);
result.addCallback(
function (response)
{
if (response.result == 'success')
{
return response.description;
//I am trying to pass this value back to the
//var test value in function one
}
}
);
}
基本上,现在我需要将response.description传回到函数一中的变量test。 任何帮助都将不胜感激。