jquery - Path JSON to return only the titles? -


hi guys i'm doing first ajax application, got lot, not hit road titles. json in way: "json.query.results.channel.item.title"

i return arrays, can not set path title, can me?

jquery:

var main = function () {     var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3d'http%3a%2f%2frss.cnn.com%2fservices%2fpodcasting%2fac360%2frss.xml'%20and%20itempath%3d%22%2f%2fchannel%22&format=json&diagnostics=true&callback=?";      $.ajax({         type: 'get',         url: url,         async: false,         jsonpcallback: 'jsoncallback',         contenttype: "application/json",         datatype: 'jsonp',         success: function (json) {             console.dir(json.query.results.channel.item);         },         error: function (e) {             console.log(e.message);         }     });      var titles = item.map(function (item) {         return item.title;      });      $(".container-list-podcast ul").append('<li>' + titles.join('</li><li>'));   }(jquery); 

jsfiddle

your item variable not defined: item have property of json.query.results.channel object available within scope of success handler. also, using async:false doesn't work jsonp, put of data processing code in success handler:

    success: function (json) {         var titles = json.query.results.channel.item.map(function (item) {             return item.title;         });         $(".container-list-podcast ul").append('<li>' + titles.join('</li><li>'));     }, 

demo: http://jsfiddle.net/eywx3/2/


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -