jquery - Retrieving stock updates using Yahoo Finance -


basically trying retrieving stock quotes specific company . in code giving symbol of specific company(eg:fb) in textbox(symb) , when click button(getupdate) should list out details regarding specific stock enter text box .

here's code :

<html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script> <script> $(document).ready(function($){ $('getupdate').click(function() {          var symbol = $('input[id=symb]').val(); \\for example:fb          var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%3d'+symbol+'&format=json&diagnostics=true&env=store%3a%2f%2fdatatables.org%2falltableswithkeys";          $.getjson(url, function(data) {             var items = [];             $.each(data.query.results.quote, function(key, val) {                 items.push('<li id="' + key + '">' + val + '</li>');              });             $('<ul/>', { 'class': 'my-new-list', html: items.join('')}).appendto('body');         }); }); }); </script>  </head> <body> <div style="padding:16px;">     stock ticker : <input id="symb" type="textbox" value="ticker"></input> </div> <button id="getupdate" name = "getupdate" type="button">get updates!</button> </body> </html> 

where going wrong ?

thanks in advance.

you have several mistakes in js code:

  1. incorrect selector button: $('getupdate') => $('#getupdate');
  2. wrong quotes inside url value;
  3. wrong query string yahoo api;
  4. wrong comment sign \\for example:fb.

your js should this:

jquery(document).ready(function($){     $('#getupdate').click(function() {             var symbol = $('input[id=symb]').val();              var url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%3d%22' + symbol + '%22&format=json&env=store%3a%2f%2fdatatables.org%2falltableswithkeys&callback=';             $.getjson(url, function(data) {                 var items = [];                 $('#results').html('');                 $.each(data.query.results.quote, function(key, val) {                     items.push('<li id="' + key + '">' + val + '</li>');                  });                 $('<ul/>', { 'class': 'my-new-list', html: items.join('')}).appendto('#results');             });     }); }); 

and please add code after <button> tag in html. clear results before new query:

<div id="results"></div> 

here example: http://jsfiddle.net/6efqk/1/

i'm not shure ouput format correct, please reformat like.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -