2010-12-02 3 views
0

jQuery 코드 : MooTools에서 어떻게이 작업을 수행합니까 (jQuery 코드)?

$.get('/', function(d) { alert($(d).find('a').length); }); 

는 특히 XMLHttpRequest를 반환 된 내용에 대한 선택기를 실행 ...

Mootools의 코드 :

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

내가 onComplete를 내부 d로 무엇을 할 수 있습니까?

답변

2

당신은

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

onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) 그래서 첫 번째라는 이름의 인수는 응답 나무가

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(); 
(그래서 실제로 선택을 통해 크롤링 할 수 html로 트리를 반환)하지만 경우 (Request.HTML를 사용할 필요가 어떤 경우 든 this

으로 유지하는 경우 언제든지 다음을 수행 할 수 있습니다. (oncomplete 내에서) console.log(this.response) 및 도착한 항목을 검사하십시오. 요소 수집 (정상 요청)이 없으면 this.response.text를 새 요소에 삽입 한 다음 선택기를 실행하십시오.

+0

$$ (html) .getElement = perfect, thanks! – Langdon

관련 문제