我用原型来做我的AJAX开发,我使用这样的代码:
somefunction: function(){
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;
}
}
});
return result;
}
Run Code Online (Sandbox Code Playgroud)
我发现"结果"是一个空字符串.所以,我试过这个:
somefunction: function(){
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;
return result;
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
但它也没有用.如何获取其他方法的responseText?