相关疑难解决方法(0)

如何返回AJAX响应文本?

我用原型来做我的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?

javascript ajax prototypejs

40
推荐指数
1
解决办法
6万
查看次数

标签 统计

ajax ×1

javascript ×1

prototypejs ×1