如何返回Ajax响应文本?我使用Prototype进行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;}我发现“结果”是一个空字符串。所以,我试过这个: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;
}
}
});}但也没用。如何获得其他方法使用的ResponseText?
2 回答
慕娘9325324
TA贡献1783条经验 获得超4个赞
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);});
添加回答
举报
0/150
提交
取消