XML的JavaScript数组与jQuery [英] XML to javascript array with jQuery

查看:111
本文介绍了XML的JavaScript数组与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的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文件,并在成功传递与<检索的数据code>每个,如:

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
                })
            }  
        }); 

这篇关于XML的JavaScript数组与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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