[ 3 posts ]

Paritosh

  • Username: paritosh123
  • Joined: Sun May 06, 2012 6:23 am
  • Posts: 1
  • Offline
  • Profile

Why autocomplete yui is not working?

Post Posted: Sun May 06, 2012 6:28 am
+0-
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 .

Scott Jungling

YUI Contributor

  • Username: sjungling
  • Joined: Fri Oct 09, 2009 8:44 am
  • Posts: 9
  • Location: Chico, CA
  • Twitter: sjungling
  • GitHub: sjungling
  • Gists: sjungling
  • IRC: sjungling
  • Offline
  • Profile

Re: Why autocomplete yui is not working?

Post Posted: Fri Jun 01, 2012 8:00 pm
+0-
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 Santini

YUI Contributor

  • Offline
  • Profile

Re: Why autocomplete yui is not working?

Post Posted: Sat Jun 02, 2012 1:46 am
+0-
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/
  [ 3 posts ]
Display posts from previous:  Sort by  
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
cron