views:

44

answers:

1

Update: This works in firefox, but does not work on chrome 6, still investigating.

I'm taking an internet programming class and learning various javascript frameworks. I'm working on a mootools problem, and the .get('text') method does not appear to be working as expected on responseXML.

Here's the responseXML:

<?xml version="1.0" encoding="UTF-8"?> 
<users> 
        <user> 
            <username>etomai</username> 
            <first_name>Joe</first_name> 
            <last_name>Smith</last_name> 
        </user> 
        <user> 
            <username>hehhh</username> 
            <first_name>hee</first_name> 
            <last_name>lkii</last_name> 
        </user> 
</users>

Here's the code:

function update_list() {
    var req = new Request({
        url: 'users.php',
        method: 'get',
        data: {
            'term': $('search').value
        },
        onComplete: function(responseText, responseXML){
            $('list').empty();
            responseXML.documentElement.getElements('user').each(function(user){
                //this seems like it should work according to all mootools docs, but it doesn't.  user.getElement('username').get('tag') works, but neither 'html' or 'text' work...retuturning undefineds.
                console.log(user.getElement('username').get('text'));
                var copy = $('template').clone();
                $('list').grab(copy);
                $(copy).removeClass('hidden');
                $(copy).getChildren()[0].set("text", "username goes here")
                $(copy).getChildren()[1].set("text", "name goes here")
            })

        }
    }).send();

}

As indicated in the comment, on the line console.log(... I should (according to documentation) be able to get the text contained in the username tag with .get('text'). Instead, its returning undefined.

Checking the value of user.getElement('username') returns the expected

<username>etomai</username>

Running code located here

Try entering the letter "e" in the search field.

I'm stuck at this juncture. Anyone able to point me in the right direction?

+1  A: 

Seems like a bug to me. On Firefox, "text" resolves to use the textContent property which is standard for an Element.

On Chrome, however, it resolves to innerText since it supports it for HTML DOM, but not for XML DOM. But we're trying to use it on an XML DOM here.

One workaround that should work for both browsers is,

user.getElement('username').textContent
Anurag