jQuery根据第一个XML读取新XML

jQuery根据第一个XML读取新XML,jquery,jquery-ui,Jquery,Jquery Ui,我有一个工作的jQuery代码,它可以读取XML 现在我需要做的是,当有人单击新闻、文章、目的地(作为示例)时,它应该读取相应的XML及其数据 例如,新闻xml应该是“data_96.xml”,文章应该是“data_97.xml”,等等 data_catid.xml的通用格式如下所示 <record> <recordId>251</recordId> <title>Czech Sandstone Chalk Ban Lifted&l

我有一个工作的jQuery代码,它可以读取XML

现在我需要做的是,当有人单击新闻、文章、目的地(作为示例)时,它应该读取相应的XML及其数据

例如,新闻xml应该是“data_96.xml”,文章应该是“data_97.xml”,等等

data_catid.xml的通用格式如下所示

<record>
    <recordId>251</recordId>
    <title>Czech Sandstone Chalk Ban Lifted</title>
    <author>|</author>
    <published>2010-01-20T14:36:00.000-08:00</published>
    <origUrl>http://www.rockandice.com/news/358-Czech-Sandstone-Chalk-Ban-Lifted</origUrl>
    <numComments>0</numComments>
    <data>&lt;![CDATA[&lt;p&gt;According to a report on czechclimbin</data>
</record>

251
捷克取消砂岩粉笔禁令
|
2010-01-20T14:36:00.000-08:00
http://www.rockandice.com/news/358-Czech-Sandstone-Chalk-Ban-Lifted
0
![CDATA[Packing根据一份关于捷克的报告
请让我知道如何更改Jquery代码以读取xmls


这是我的Jquery代码

<script type='text/javascript'>
  //<![CDATA[ 
  $(window).load(function(){

  $.ajax({
    url:'data.xml',
    dataType: 'xml',
    type:'post',
    success: function(data){
        var xml = $(data);
        $('#container').append( CategoryToUl(xml.children()) );

    }
});

function CategoryToUl(xml){
    var categories = xml.children('category');
    if (categories.length > 0)
    {
        var ul = $('<ul/>');
        categories.each(function(){
            var $this = $(this);
            var li = $('<li/>');
            var a = $('<a/>',{
                text: $this.children('title').text(),
                href: '#' + $this.children('catId').text()
            });
            li.append(a);
            li.append( CategoryToUl( $this ) );
            ul.append(li);
        });
        return ul;
    }
    return null;
}

  });
  //]]> 
  </script>

</head>
<body>
  <div id="container"></div>

</body>

// 0)
{
var ul=$(“
    ”); 类别。每个(函数(){ var$this=$(this); 变量li=$(“
  • ”); 变量a=$(''{ text:$this.children('title').text(), href:“#”+$this.children('catId').text() }); li.附加(a); li.附加(分类($this)); ul.附加(li); }); 返回ul; } 返回null; } }); //]]>
您只需添加如下内容:

<script type='text/javascript'>
  //<![CDATA[ 
  $(window).load(function(){

$('a').live('click', function() {
    var catId = $(this).attr('href').replace('#', '');    
    //here you can use $.get to get your new xml file. 
    //construct the url using the catid
    //you would then parse the xml to display it.
});

//here is the rest of your code


// 您可以在链接生成时更改
CategoryToUl
方法

var a = $('<a/>',{
    text: $this.children('title').text(),
    href: '#',
    'data-id': $this.children('catId').text(),
    class='categoryrecord'
});

你能包括你的jquery代码吗?我已经添加了jquery代码,请检查并让我知道需要更改什么。。。
$('a.categoryrecord').live('click',function(e){
   e.preventDefault();
   var cid = $(this).data('id');
   $.ajax({
      url:'data_' + cid + '.xml',
      dataType: 'xml',
      type:'post',
      success: function(data){
          var xml = $(data);
          // .. do what you want here with the xml
      }
   });
});