XML的JavaScript数组与jQuery数组、XML、JavaScript、jQuery

由网友(吃了跳跳糖的僵尸)分享简介:我是新来的XML和AJAX和我只是一个初来乍到的Javascript和jQuery。在其他工作职责我设计我们的网站。一个最后期限非常近,我能想到的唯一办法做这个项目以及与AJAX。我有充分的XML对象的证件,如这一个重复的:I am new to XML and AJAX and am only a newcomer...

我是新来的XML和AJAX和我只是一个初来乍到的Javascript和jQuery。在其他工作职责我设计我们的网站。一个最后期限非常近,我能想到的唯一办法做这个项目以及与AJAX。我有充分的XML对象的证件,如这一个重复的:

I am new to XML and AJAX and am only a newcomer to Javascript and jQuery. Among other job duties I design our website. A deadline is very near, and the only way I can think of to do this project well is with AJAX. I have a document full of XML objects such as this one repeating:

<item>
    <subject></subject>
    <date></date>
    <thumb></thumb>
</item>

我要创建的所有元素和它们的子元件的阵列。我一直在阅读关于AJAX几个小时jQuery的教程,甚至不知道从哪里开始,因为他们都认为JavaScript的能力一定水平。如果有人能告诉我最简单的方法,通过所有的元素循环,并把自己的孩子到一个数组,我AP preciate它吨。

I want to create an array of all elements and their child elements. I've been reading jQuery tutorials on AJAX for hours and don't even know where to start because they all assume a certain level of javascript proficiency. If someone could show me the easiest way to loop through all elements and put their children into an array, I'd appreciate it tons.

推荐答案

使用jQuery, $。阿贾克斯() XML文件,并在成功传递与每个,如:

Using jQuery, $.ajax() your XML file, and on success pass retrieved data with each, like:

 var tmpSubject, tmpDate, tmpThumb;
 $.ajax({
            url: '/your_file.xml',
            type: 'GET', 
            dataType: 'xml',
            success: function(returnedXMLResponse){
                $('item', returnedXMLResponse).each(function(){
                     tmpSubject = $('subject', this).text();
                     tmpDate = $('date', this).text();
                     tmpThumb = $('thumb', this).text();
                    //Here you can do anything you want with those temporary
                    //variables, e.g. put them in some place in your html document
                    //or store them in an associative array
                })
            }  
        }); 
阅读全文

相关推荐

最新文章