title: How to make jquery auto suggest with JSON data returned from API call
body: <p>I want to make a autosuggest function while entering 3 char in text input box. the suggestion list should be populated from JSON data result from API call.</p>
  
  <p>my input textbox code is below:</p>
  
  <pre><code>&lt;div&gt;&lt;input id="trnnumname"&gt;&lt;/input&gt;&lt;/div&gt;
  </code></pre>
  
  <p>This is my API url:</p>
  
  <pre><code>http://api.railwayapi.com/suggest_train/trains/190/apikey/1234567892/
  </code></pre>
  
  <p>which give result after API call completes in the form of JSON data. In URL <strong>190</strong> is train number based on that result comes which show all the trains who has number starting from 190**.</p>
  
  <p>below is JSON result:</p>
  
  <pre><code>{
  "response_code": 200,
  "train": [
      "19005 (SAURASHTRA MAIL)",
      "19006 (SAURASHTRA MAIL)",
      "19011 (GUJARAT EXPRESS)",
      "19012 (GUJARAT EXPRESS)",
      "19017 (SAU JANATA EXP)",
      "19018 (SAU JANATA EXP)",
      "19019 (DEHRADUN EXP)",
      "19020 (DEHRADUN EXP)",
      "19021 (BDTS LJN EXPRES)",
      "19022 (LJN BDTS EXP)",
      "19023 (FZR JANATA EXP)",
      "19024 (FZR BCT JANTA)",
      "19027 (VIVEK EXPRESS)",
      "19028 (VIVEK EXPRESS)",
      "19029 (BDTS DEE EXPRES)",
      "19030 (DEE BDTS EXP)",
      "19031 (HARIDWAR MAIL)",
      "19032 (YOGA EXPRESS)",
      "19033 (GUJARAT QUEEN)",
      "19034 (GUJARAT QUEEN)",
      "19037 (AVADH EXPRESS)",
      "19038 (AVADH EXPRESS)",
      "19039 (AVADH EXPRESS)",
      "19040 (AVADH EXPRESS)",
      "19045 (TAPTI GANGA EXP)",
      "19046 (TAPTI GANGA EXP)",
      "19047 (ST BHAGALPUR EX)",
      "19048 (BGP SURAT EXP)",
      "19049 (BDTS PATNA EXP)",
      "19050 (PNBE BDTS EXP)",
      "19051 (SHRAMIK EXPRESS)",
      "19052 (BL SHRAMIK EXP)",
      "19053 (ST MFP EXPRESS)",
      "19054 (MFP ST EXPRESS)",
      "19055 (BL JODHPUR EXP)",
      "19056 (JU BL EXPRESS)",
      "19057 (UDN VARANASI EX)",
      "19058 (BSB UDN EXP)",
      "19059 (JAMNAGAR INTCIT)",
      "19060 (SURAT INTERCITY)",
      "19061 (RAMNAGAR EXPRES)",
      "19062 (RMR BDTS EXP)",
      "19063 (DANAPUR EXPRESS)",
      "19064 (DNR UDHNA  EXP)",
      "19065 (BDTS BGKT EXP)",
      "19066 (BGKT BDTS EXP)"
  ],
  "total": 46 }
  </code></pre>
  
  <p>I want to use the above result as suggestion list. i tried to use Jquery auto-suggestion API code but not able to configured it properly.</p>
  
  <p>Pls give full code including all libraries required. Any help is highly solicited.</p>
  
  <p>my code is:</p>
  
  <pre><code>&lt;script&gt;$(function(){ $.getJSON('http://allorigins.pw/get?url=' + encodeURIComponent('http://api.railwayapi.com/suggest_train/trains/' + $('#trnnumname').value() + '/apikey/12345678/') + '&amp;callback=?', function(data){varjdata = JSON.parse(data.contents);alert("1");varjdata1 = varjdata.train;});$("#trnnumname").autocomplete({source: varjdata1,minLength: 3,delay: 500});});&lt;/script&gt;
  </code></pre>