使用jquery和YQL的跨域xml不起作用

最近,我遇到了一个应该加载和解析外部XML的脚本,然而,由于我是一个初学者,我以为如果我只更改XMLURL,它可能会起作用,但它没有.
我需要做的是:解析XML,这样它就可以显示为HTML.
我还尝试了许多不同的外部XML,但都没有成功.我当前的XML url是:
Http://bws.buscape.com/service/offer...Id=5889&page=1
我试着在Js菲德尔中配置脚本,但不起作用.因此,您可以使用以下站点:
Http://www.compileonline.com/try_javascript_online.php
要运行该脚本:

选择 | 换行 | 行号
  1. <!DOCTYPE html> 
  2. <html> 
  3.     <head> 
  4.     <title>Cross XML Sample</title> 
  5.  
  6.     <meta name="viewport" content="width=device-width, initial-scale=1"> 
  7.  
  8.     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
  9.     <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  10.     <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
  11.     <script src="xml2json.js"></script>
  12.     <script src="jquery.xdomainajax.js"></script>
  13.     <script>
  14.  
  15.  
  16. <!--    XMLs de amostra: 
  17. // http://www.w3schools.com/xml/cd_catalog.xml
  18. // http://bws.buscape.com/service/offers/lomadee/65717751673178504d42633d/BR/?sourceId=28400481&advertiserId=5889&page=1
  19. -->
  20.  
  21.         // For This example, im going to use sample xml from o'reily for practice
  22.         // located at url http://examples.oreilly.com/9780596002527/examples/first.xml
  23.         // We are going to extract character name nodes for this sample
  24.         function xmlLoader(){
  25.             $.ajax({
  26.                 url: 'http://examples.oreilly.com/9780596002527/examples/first.xml',
  27.                 dataType: "xml",
  28.                 type: 'GET',
  29.                 success: function(res) {
  30.                     var myXML = res.responseText;
  31.                     // This is the part xml2Json comes in.
  32.                     var JSONConvertedXML = $.xml2json(myXML);
  33.                     $('#myXMLList').empty();
  34.                     for(var i = 0; i < JSONConvertedXML.book.character.length; i++){
  35.                         $('#myXMLList').append('<li><a href="#">'+JSONConvertedXML.book.character[i].name+'</a></li>')
  36.                     }
  37.                     $('#myXMLList').listview('refresh');
  38.                     $.mobile.hidePageLoadingMsg();
  39.                 }
  40.             });
  41.         }
  42.  
  43.         $( document ).delegate("#home", "pageshow", function() {
  44.             $.mobile.showPageLoadingMsg();
  45.             xmlLoader();
  46.         });
  47.     </script>
  48. </head> 
  49.  
  50. <body> 
  51.     <div data-role="page" id="home"> 
  52.         <div data-role="header">
  53.             <h1>Sample Cross Domain XML</h1>
  54.         </div> 
  55.         <div data-role="content">
  56.             <ul data-role="listview" data-theme="c" id="myXMLList">
  57.  
  58.             </ul>
  59.         </div> 
  60.         <div data-role="footer">
  61.             <a href="www.isgoodstuff.com" data-role="button">isGoodStuff.com</a>
  62.         </div> 
  63.     </div>
  64. </body>
  65. </html>

标签: Javascript

添加新评论