Bootstrap typeahead not working

I am pulling stock symbols from Yahoo finance in a json object and I am trying to show them as a drop-down menu while the user starts typing the name of the company or the symbol in the search box . Typeahead is not working as a drop down menu from the search box. I think I am doing everything right.This is the code I have so far. Any help is appreciated.

[PHP]$(document).ready(function() {

// create autocomplete
$(’#form-quote input[name=symbol]’).typeahead({

  // load autocomplete data from suggest.php
  source: function(query, callback) {
          url: '../suggest.php',
          type: 'POST',
          dataType: 'json',
          data: {
              symbol: query
          success: function(response) {



// load data via ajax when form is submitted
$(’#form-quote’).on(‘click’, function() {

  // determine symbol
  var symbol = $('#form-quote input[name=symbol]').val();

  // send request to quote.php
      url: 'quote.php',
      type: 'POST',
      data: {
          symbol: symbol
      success: function(response) {

  return false;






//if form was submitted


$stock = lookup(strtoupper($_POST["symbol"]));


    //echo "You must enter a stock symbol";

}else if($_POST["symbol"]){

$price = number_format($stock['price'], 2);

echo "A share of {$stock['name']} costs $$price";



// render portfolio

render(“stock_search.php”, [“title” => “Get Quote”]);



<div class="control-group">
    <button type="submit" class="btn">Get Quote</button>



// configuration

// if form was submitted
// load suggestion data
$data = @file_get_contents(“ {$_POST[‘symbol’]}&region=US&lang=en-US&callback=YAHOO.util.ScriptNodeDataSource.callbacks”);

// parse yahoo data into a list of symbols

$result = [];
$json = json_decode(substr($data, strlen(‘YAHOO.util.ScriptNodeDataSource.callbacks(’), -1));
foreach ($json->ResultSet->Result as $stock)
$result[] = $stock;

echo json_encode(['symbols' => $result]);



Do you have a url to test? Why are you suppressing errors on file_get_contents()?

You can view the project here and use username: skroob and password 12345 . I am not suppressing any errors. If I put a symbol instead of {$_POST[‘symbol’]} I get back a json object. But for some reason its not showing them as a drop-down menu.


The @ means to ignore errors. You shouldn’t use it unless you expect errors and have already coded around them. Remove it and see if file_get_contents is returning any errors.

I removed the @ and I don’t get any errors. Do I have to do anything to support ajax on the machine?

I just checked the ‘Quote’ section and it appears to be working for me.

It works if I type the right stock symbol. I am trying to have it display a drop-down list of possible matches while the user is typing.

Are you sure? If I type “GO” it displays “GOOG” on the drop down, along with many others.

I made a file with all the stock symbols and typeahead is looking into that file. I couldn’t get ajax to work.

Sponsor our Newsletter | Privacy Policy | Terms of Service