remember that onComplete is called long after the someFunction is done working. What you need to do is pass a callback function to the somefunction as a parameter. This function will be called when the process is done working (ie, onComplete):
somefunction: function(callback){
var result = "";
myAjax = new Ajax.Request(postUrl, {
method: 'post',
postBody: postData,
contentType: 'application/x-www-form-urlencoded',
onComplete: function(transport){
if (200 == transport.status) {
result = transport.responseText;
callback(result);
}
}
});
}
somefunction(function(result){
alert(result);
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…