How do you grab an element from a remote page using MooTools and Request.HTML?
I'm using MooTools ( part of the project ) to load a page usi开发者_StackOverflow中文版ng Request.HTML
which works fine except that I don't want the whole page, just one fragment which has an id.
This is the code in question
var req = new Request.HTML({
onSuccess: function( res ) {
// according to the docs
// res should be the node list of the remote response
// I want to grab #myFragment
var f = res.getElementById('myFragment');
// res.getElementById is not a function
var f = $(res).getElementById('myFragment');
// $(res) is null ?
var f = $$(res).getElementById('myFragment');
// [null, null] ??
// more code
}
}).get('/myurl');
I'm pretty sure this must be possible, I can grab elements that have a class. Does anyone know how to do this.
Thanks )
I hopped onto the #mootools channel on irc.freenode.net and got my answer from <kamicane> himself
var req = new Request.HTML({
onSuccess: function( responseTree, responseElements /*more*/ ) {
// responseElements is the one I want
//it's an array of elements which you can filter
var f = responseElements.filter('#myFragment');
// do stuff with my fragment
}
}).get('/myurl');
I'm not familiar with Mootools but when digging into Request.HTML documentation found this:
Request success event: onSuccess(responseTree, responseElements, responseHTML, responseJavaScript)
and
responseElements - (array) An array containing all elements of the remote response.
Hope this would give right direction to solve your problem.
精彩评论