开发者

How do you do this (jQuery code) in MooTools?

jQuery code:

$.get('/开发者_Go百科', function(d) { alert($(d).find('a').length); });

Specifically running a selector on the returned content of an XMLHttpRequest...

MooTools code:

var opt = { url : '/', onComplete : function(d) { alert(d); } };
new Request(opt).send();

What do I do with d inside of onComplete?


you need to use Request.HTML though (so it actually returns the html tree that a selector can crawl through)

new Request.HTML({
    url: '/',
    method: 'get',
    onComplete: function() {
        // normalise the collection so we can apply methods to it. 
        console.log($$(this.response.tree).getElement("a.foo")); // or getElements()
    }
}).send();

http://www.jsfiddle.net/dimitar/NF2jz/477/

onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) so first named arg is your response tree (if you are keeping this bound to something else)

in any case, you can always do: (within the onComplete) console.log(this.response) and inspect what arrives. if no element collection (normal request) then you can inject this.response.text into a new element and then run the selector on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜