views:

1699

answers:

2

How do you access the response from the Request object in MooTools? I've been looking at the documentation and the MooTorial, but I can't seem to make any headway. Other Ajax stuff I've done with MooTools I haven't had to manipulate the response at all, so I've just been able to inject it straight into the document, but now I need to make some changes to it first. I don't want to alert the response, I'd like to access it so I can make further changes to it. Any help would be greatly appreciated. Thanks.

Edit:

I'd like to be able to access the response after the request has already been made, preferably outside of the Request object. It's for an RSS reader, so I need to do some parsing and Request is just being used to get the feed from a server file. This function is a method in a class, which should return the response in a string, but it isn't returning anything but undefined:

        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;
        }
A: 

Is this what you're looking for?

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();
Grant Wagner
Close, but not quite. I'm able to get that to work, but I don't want to just alert the response, I want to access it outside the Request object after I get it.
VirtuosiMedia
+1  A: 

I was able to find my answer on the MooTools Group at Google.

VirtuosiMedia