1

您如何访问 MooTools 中 Request 对象的响应?我一直在查看文档和 MooTorial,但似乎没有取得任何进展。我用 MooTools 完成的其他 Ajax 东西我根本不需要操纵响应,所以我可以直接将它注入到文档中,但现在我需要先对其进行一些更改。我不想提醒响应,我想访问它,以便可以对其进行进一步更改。任何帮助将不胜感激。谢谢。

编辑:

我希望能够在请求已经发出后访问响应,最好是在 Request 对象之外。它用于 RSS 阅读器,因此我需要进行一些解析,而 Request 只是用于从服务器文件中获取提要。这个函数是一个类中的一个方法,它应该以字符串的形式返回响应,但它除了未定义之外什么都不返回:

        fetch: function(site){
                var feed;
                var req = new Request({
                        method: this.options.method,
                        url: this.options.rssFetchPath,
                        data: { 'url' : site },
            onRequest: function() {
                                if (this.options.targetId) { $
(this.options.targetId).setProperty('html',
this.options.onRequestMessage); }
                        }.bind(this),
                        onSuccess: function(responseText) {
                                feed = responseText;
                        }
                });
                req.send();
                return feed;
        } 
4

2 回答 2

2

响应内容返回给 onComplete 中定义的匿名函数。

可以从那里访问它。

var req = new Request({
    method: 'get',
    url: ...,
    data: ...,
    onRequest: function() { alert('Request made. Please wait...'); },

    // the response is passed to the callback as the first parameter
    onComplete: function(response) { alert('Response: ' + response); }

}).send();  
于 2008-09-18T20:30:44.257 回答
0

我可以在 Google 的 MooTools Group上找到我的答案。

于 2008-09-18T21:23:20.373 回答