:这在Firefox中有效,但在Chrome6上无效,仍在调查中。
我正在上网络编程课,学习各种JavaScript框架。我正在处理一个moootools问题,.get(“text”)方法在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>
代码如下:
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();
}
如注释所示,在第行
console.log(...
我应该(根据文档)能够使用
.get('text')
. 相反,它返回未定义。
检查的值
user.getElement('username')
返回预期的
<username>etomai</username>
找到运行代码
here
尝试在搜索字段中输入字母“e”。
我被困在这个关头。有人能指出我的正确方向吗?