AJAX&Javascript&XML:将DOM元素添加到数组不起作用 [英] AJAX & Javascript & XML: adding DOM elements to array not working

查看:41
本文介绍了AJAX&Javascript&XML:将DOM元素添加到数组不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Flickr中获取一些XML,并希望基于DOM对其进行解析.无法使我的代码与以下代码一起使用:

I am fetching some XML from Flickr and want to parse it based on DOM. can't get my code to work with the following:

...
if (this.responseXML != null)
    {
        content = this.responseText.getElementsByTagName('content')
        for (i = 0 ; i < content.length ; i++)
        {
            out += content[i].childNodes[0].nodeValue + '<br />'
        }
        document.getElementById('info').innerHTML = out
        }
...

这将返回呼叫的全部内容:

this however returns the full content of the call:

...
if (this.responseXML != null)
    {
        document.getElementById('info').innerHTML =
            this.responseText
            }
...

这使我认为我的AJAX代码是正确的,但是我在解析代码中做错了事

which leads me to think that my AJAX code is correct but that i'm doing something wrong in the parsing code

注意:这与另一条帖子有关.问题是另外一个

Note: this is related another post althought he problem is a different one

推荐答案

问题似乎是给了您一个字符串而不是一个XML DOM对象.为了创建XML DOM对象,您需要解析XML字符串.此stackoverflow线程有一些很好的代码和讨论,说明了解析XML的最佳方法可能是什么是.

The problem seems to be that you're given a string rather than an XML DOM object. In order to create a XML DOM Object, you'll need to parse the XML string. This stackoverflow thread has some good code and discussion as to what the best way to parse the XML might be.

这篇关于AJAX&amp;Javascript&amp;XML:将DOM元素添加到数组不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆