Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
jQuery(document).ready(function () {
    jQuery.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22YHOO%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=',
        function (data) {
            alert(query[0].results[0].quote.symbol);
        });
});



Now i am getting a alert as undefined if i print the data in console i am getting all values json values also..

My problem is i want to display all values
symbol   "YHOO"
AverageDailyVolume  "17498000"
Change  "-0.29"
DaysLow "38.1131"
DaysHigh  "38.45"
YearLow  "20.58"
YearHigh "41.72"
MarketCapitalization "39.712B"
LastTradePriceOnly "38.23"
DaysRange "38.1131 - 38.45"
Name "Yahoo Inc."
Symbol "YHOO"
Volume "9987016"
StockExchange "NasdaqNM"



JavaScript
jQuery(document).ready(function () {
    jQuery.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22YHOO%22%2C%22BHI%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=',
        function (data) {
            var length = data.query.results.quote.length;
            //alert(length);
            for (i = 0; i < length; i++) {
                alert(data.query.results.quote[i].symbol);
            }
        });

});


Now i want to display all values inside quote now it is displaying only symbol any idea means help me..
Posted
Updated 15-Feb-14 7:43am
v5

JavaScript
alert(data.query.results.quote.symbol);



I have solved myself now if any one found any good solution please help me.
 
Share this answer
 
Comments
I was writing the same thing for you. After adding, I saw your answer. You can see that below.
You can accept that also.
JavaScript
jQuery(document).ready(function () {
    jQuery.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22YHOO%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=',
        function (data) {
            alert(query[0].results[0].quote.symbol);
            // Get all results from argument "data", not like above.
        });
});
 
Share this answer
 
Comments
shajis001 15-Feb-14 8:30am    
Can you explain it briefly

If i give alert(data); i am getting a prompt [object Object]
No, I said you have to get it from "data", as you have already did in your answer.
I don't have a laptop now, otherwise I could have said the exact answer.

You are using query[0]...., which was wrong.
shajis001 15-Feb-14 13:26pm    
But tadit one more help quote containing symbol "YHOO"
AverageDailyVolume "17498000"
Change "-0.29"
DaysLow "38.1131"
DaysHigh "38.45"
YearLow "20.58"
YearHigh "41.72"
MarketCapitalization "39.712B"
LastTradePriceOnly "38.23"
DaysRange "38.1131 - 38.45"
Name "Yahoo Inc."
Symbol "YHOO"
Volume "9987016"
StockExchange "NasdaqNM"

this much value how can i display all
shajis001 15-Feb-14 13:30pm    
I tried creating one array
var stockVal = ["symbol","Name","Change"];

I want to get this much vallue.
When i am trying to check the length of data

console.log(data.query.results.quote.length);


is displaying 1 actually i want to get the length of attributes inside quote how can i do this..
I have to test on Developer Tool by debugging. Will reply you tomorrow. :)
 <script><br />
       jQuery(document).ready(function () {<br />
            jQuery.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22BHI%22%2C%22IBM%22%2C%22HHZ14.NYM%22%2C%22AYJ14.NYM%22%2C%22CLM17.NYM%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=',<br />
                function (data) {<br />
                    var length = data.query.results.quote.length;<br />
                    console.log(data);<br />
                    var symbol = [];<br />
                    var change = [];<br />
                    var commName = [];<br />
                    var lastPrice = [];<br />
                    for (i = 0; i < length; i++) {                       <br />
                        symbol.push(data.query.results.quote[i].symbol);<br />
                        change.push(data.query.results.quote[i].Change);<br />
                        commName.push(data.query.results.quote[i].Name)<br />
                        lastPrice.push(data.query.results.quote[i].LastTradePriceOnly);<br />
                    }                  <br />
                    for(j = 0; j<change.length; j++)<br />
                    {<br />
                        var sign = change[j].substr(0, 1);<br />
                        if (sign === '-') {<br />
                           <br />
                            $('table').append('<tr><td>' + symbol[j] + '</td> <td>' + lastPrice[j] + '</td>  <td style="color:green">' + change[j] + '</td> </tr>');<br />
                           <br />
                        } else {<br />
                            $('table').append('<tr><td>' + symbol[j] + '</td> <td>' + lastPrice[j] + '</td>  <td style="color:red">' + change[j] + '</td> </tr>');<br />
                           <br />
                        }<br />
                        <br />
                   }                 <br />
<br />
                });<br />
        });<br />
    </script><br />
<br />
    <h2> Commodity Prices </h2><br />
    <style><br />
        font-family:'droid_sansregular';<br />
    </style><br />
    <table width="227" border="1" margin-top="-16px"><br />
        <tr style="border:none;"><br />
            <td><div align="center">  Stock  </div></td><br />
            <td><div align="center"> Value  </div></td><br />
            <td><div align="center"> Change  </div></td><br />
        </tr><br />
        <tr style="border:none;" class="add">                   <br />
        </tr><br />
<br />
    </table> 
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900