By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

Cross domain xml using jquery and YQL not working

matheussousuke
100+
P: 249
Recently I came across an script that is supposed to load and parse external xml, however, as I'm a beginner, I presumed if I just changed the xml url, it might work, but it didn't.

What I need to do: Parse the xml so it can be displayed as HTML.

I also tried with many different external xmls, with no success. My current xml url is: http://bws.buscape.com/service/offer...Id=5889&page=1

I tried configuring the script in Js Fiddle, but it didn't work. So you can use the following site: http://www.compileonline.com/try_javascript_online.php to run the script:

Expand|Select|Wrap|Line Numbers
  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>
May 31 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.