Question

I have a script (javascript) that I'm using to pull data via YQL. Everything works fine when I put the raw query into the YQL console, but using the provided URL in my script, I get different results.

Check it out here: http://jsfiddle.net/thetuneupguy/t2JCB/

$(function() {
    $.getJSON('http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yahoo.finance.quotes%20WHERE%20symbol%20in(%22GCF14.CMX%22%2C%22SIF14.CMX%22%2C%22PAH14.NYM%22%2C%22PLF14.NYM%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?', function(data) {
        var items = [];
        console.log(data);
        $.each(data, function() {
            $.each(this, function(name, value) {
                /// Do what ever here...
                items.push('<li id="' + name + '">' + value + '</li>');
                console.log(name + '=' + value);
            });

        });
        $('<ul/>', {
            'class': 'my-new-list',
            html: items.join('')
        }).appendTo('body');
    });
});

Any ideas of what I'm doing wrong?

Was it helpful?

Solution

$(function() {
    $.getJSON('http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yahoo.finance.quotes%20WHERE%20symbol%20in(%22GCF14.CMX%22%2C%22SIF14.CMX%22%2C%22PAH14.NYM%22%2C%22PLF14.NYM%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?', function(data) {

        console.log(data.query.results.quote);
        $.each(data.query.results.quote,function(key,val){
            var items = [];
            $.each(val,function(name,value){
            items.push('<li id="' + name + '">' + value + '</li>');
            });
        $('<ul/>', {'class': 'my-new-list',html: items.join('')}).appendTo('body');
        });

    });
});

this should get you on the right track. the quote object is in a bit deeper.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top