title: How to load JSON data to use it with select2 plugin
body: <p>I want to use select2 plugin for my project. I followed <strong><a href="http://select2.github.io/examples.html">this</a></strong> example, but it doesn't work for me.</p>
  
  <p><strong>JSON output</strong> :</p>
  
  <pre><code>[
      {"ime":"BioPlex TM"},
      {"ime":"Aegis sym agrilla"},
      {"ime":"Aegis sym irriga"},
      {"ime":"Aegis sym microgranulo"},
      {"ime":"Aegis sym pastiglia"},
      {"ime":"Agroblen 15816+3MgO"},
      {"ime":"Agroblen 18816+3MgO"},
      {"ime":"Agrobor 15 HU"},
      {"ime":"Agrocal (Ca + Mg)"},
      {"ime":"Agrocal (Ca)"},
      {"ime":"Agrogold"},
      {"ime":"Agroleaf Power 12525+ME"},
      {"ime":"Agroleaf Power 151031+ME"},
      {"ime":"Agroleaf Power 202020+ME"},
      {"ime":"Agroleaf Power 311111+ME"},
      {"ime":"Agroleaf Power Ca"},
      {"ime":"Agrolution 14714+14 CaO+ME"},
      {"ime":"Agrovapno dolomitno"},
      {"ime":"Agrovit HSF"},
      {"ime":"Agrovit P"},
      {"ime":"Agrozin 32 T"},
      {"ime":"Albatros Hydro"},
      {"ime":"Albatros Sprint"},
      {"ime":"Albatros Standard"},
      {"ime":"Albatros Universal"},
      {"ime":"Algaren"},
      {"ime":"AlgoVital ? Plus"},
      {"ime":"Amalgerol PREMIUM"},
      {"ime":"Amcolon \/ Novalon"},
      {"ime":"Amcopaste"},
      {"ime":"Aminosprint N8"},
      {"ime":"AminoVital"},
      {"ime":"Ammonium nitrate 33.5%"},
      {"ime":"Ammonium nitrate with calcium sulfate"},
      {"ime":"Ammonium sulfate"}
  ]
  </code></pre>
  
  <p><strong>Script</strong> :</p>
  
  <pre><code>function formatDjubrivo(data) {
      return data;
  }
  function formatDjubrivo1(data) {
      return data.ime;
  
  $( "#inputs" ).change(function() {
      console.log('prolazi klik');
      var t = $( this ).val();
      console.log(t);
      if (t=='djubrivo') {
         console.log('prolazi klik if');
         $('#stavka').select2({
            ajax: {
               dataType : "json",
               url      : "djubrivo.php",
               results  : function (data) {
                   return {results: data};
               }
            },
            formatResult : formatDjubrivo
         });
      }else {
         console.log('nije djubrivo');
      }
  });
  </code></pre>
  
  <p><strong>HTML</strong> :</p>
  
  <pre><code>&lt;div class="col-md-2" style="padding-right:0px;"&gt;
      Vrsta Inputa
      &lt;select id="inputs" name="inputs" class="form-control js-example-responsive"&gt;
          &lt;option value="djubrivo"&gt;djubrivo&lt;/option&gt;
          &lt;option value="pesticidi"&gt;pesticidi&lt;/option&gt;
          &lt;option value="kultura"&gt;kultura&lt;/option&gt;
          &lt;option value="voda"&gt;voda&lt;/option&gt;
      &lt;/select&gt;
  &lt;/div&gt;
  
  &lt;div class="col-md-2" style="padding-right:0px;"&gt;
      Stavka
      &lt;input id="stavka" name="stavka" class="form-control js-example-responsive"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the result when I test my code using <code>console.log</code>:</p>
  
  <blockquote>
    <p>Select2: The AJAX results did not return an array in the <code>results</code> key of the response.</p>
  </blockquote>
  
  <p>Where did I made mistake?</p>