How to I parse multiple items using jQuery and Ajax?

I'm trying to parse multiple items from an XML file using jQuery Ajax for the xml structure: 1 2 3 where each `` has a different number of authors (or, not shown in the example above, also a varying number of topics). My exact jQuery and XML are below. What is happening with my current code is that all ``'s are being listed for each item, instead of only the ``'s for that specific `` being listed. If you can help me with this, I would really appreciate it. In addition to the above, I also need to have a specific url for each `` and a specific url for each ``. I don't have these urls in the below XML yet. Could you show me how to add that specific URL for each `` and ``? Thank you very much! XML: This is one title This is an example of a subtitle Steve Johnson Michael Smith Technology This is another title This is an example of a subtitle John Williams Management Info Systems jQuery: $.ajax({ type: "GET", dataType: "xml", cache: false, async: false, url: xmlTitlesContent, success: parTitlesCon, error: parseError }); function parTitlesCon(xml) { $(xml).find('titleitem').each(function(){ var id = $(this).attr('id'); var title = $(this).find('title').text(); var subtitle = $(this).find('subtitle').text(); var imagelg = $(this).find('imagelg').text(); var url = $(this).find('url').text(); $('') .html('
'+title+'
'+subtitle+'
By
Topics
') .appendTo('#contentloaded'); $(this).find('authors').each(function(){ var author = $(this).find('author').text(); $('').html(author).appendTo('div.itemauthor'); }); $(this).find('topics').each(function(){ var topic = $(this).find('topic').text(); $('
').html(topic).appendTo('div.itemtopiclist'); }); }); } function parseError() { // Error Message var parseErrorMessage = 'There was a problem loading the content. Please try again later.'; // Append Notice in Content Body $('#contentloaded').append('Not content available'); // Append Popup to Body $('body').append('
'+ parseErrorMessage +'
'); // FadeIn/FadeOut Popup $('div.ariasXMLLoadError').fadeIn(200).delay(3000).fadeOut('slow', function(){ $(this).remove(); }); }
Can you provide a sample output? What do you want the output to look like ideally? Just plugged it into jsfiddle and got This is an example of a subtitle Steve Johnson Michael Smith Technology This is an example of a subtitle John Williams Management Info Systems

以上就是How to I parse multiple items using jQuery and Ajax?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏