| Page 1 of 1 | [ 3 posts ] |
|
I am trying to setup autocomplete yahoo finance quotes.Below the code of the files.
**test.php** Code: <script src="http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js"></script> <div id="demo" class="yui3-skin-sam"> <label for="ac-input">Enter company name</label><br> <input id="ac-input" type="text"> </div> <script> YUI().use('autocomplete', 'autocomplete-highlighters', function (Y) { Y.one('#ac-input').plug(Y.Plugin.AutoComplete, { resultHighlighter: 'phraseMatch', resultListLocator: 'ResultSet.Result', resultTextLocator: 'name', source: 'test2.php?symbol={query}&callback={callback}' }); }); </script> **test2.php** Code: <?php $query = $_GET['symbol']; $url = "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query={$query}&callback=YAHOO.Finance.SymbolSuggest.ssCallback"; $yss = file_get_contents($url,"r"); echo $yss; I dont understand why the above code is not working. **test.php** file is getting proper response from test2.php still file autocomplete box is not showing. <br /> **Response looks like** Code: YAHOO.Finance.SymbolSuggest.ssCallback({"ResultSet":{"Query":"g","Result":[{"symbol":"G","name": "Genpact Ltd.","exch": "NYQ","type": "S","exchDisp":"NYSE","typeDisp":"Equity"},{"symbol":"GMCR","name": "Green Mountain Coffee Roasters Inc.","exch": "NMS","type": "S","exchDisp":"NASDAQ","typeDisp":"Equity"},{"symbol":"^GSPC","name": "S&P 500","exch": "SNP","type": "I","typeDisp":"Index"},{"symbol":"GOOG","name": "Google Inc.","exch": "NMS","type": "S","exchDisp":"NASDAQ","typeDisp":"Equity"},{"symbol":"AIG","name": "American International Group, Inc.","exch": "NYQ","type": "S","exchDisp":"NYSE","typeDisp":"Equity"},{"symbol":"GE","name": "General Electric Company","exch": "NYQ","type": "S","exchDisp":"NYSE","typeDisp":"Equity"},{"symbol":"GLD","name": "SPDR Gold Shares","exch": "PCX","type": "E","typeDisp":"ETF"},{"symbol":"KOG","name": "Kodiak Oil & Gas Corp.","exch": "NYQ","type": "S","exchDisp":"NYSE","typeDisp":"Equity"},{"symbol":"^GDAXI","name": "DAX","exch": "GER","type": "I","exchDisp":"XETRA","typeDisp":"Index"},{"symbol":"FCX","name": "Freeport-McMoRan Copper & Gold Inc.","exch": "NYQ","type": "S","exchDisp":"NYSE","typeDisp":"Equity"}]}}) Please explain . |
|
I think this is stemming from the fact that the Response you get is actually JSON wrapped in callback function. Generally the AutoComplete widget defines it's own callback method. As such, the Widget is trying to parse this text assuming it's JSON, but finding a javascript function instead.
If your PHP can strip off "YAHOO.Finance.SymbolSuggest.ssCallback(" and the closing ")" then you might have some more luck. |
Alberto SantiniYUI Contributor
|
Hello Paritosh.
You can give a look at "Yahoo! Finances and Google Finance Get Quotes AutoComplete" examples [1]. Hope that helps, IceBox. [1] http://albertosantini.github.com/ |
| Page 1 of 1 | [ 3 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group