title: jquery select2: error in getting data from php-mysql
body: <p>I am testing <strong>select2</strong> plugin in my local machine. 
  But for some reason. it is not collecting the data from database. </p>
  
  <p>I tried multiple times but not able to find the issue. </p>
  
  <p>Below are the code .</p>
  
  <pre><code>&lt;div class="form-group"&gt;
  
     &lt;div class="col-sm-6"&gt;
         &lt;input type="hidden" id="tags" style="width: 300px"/&gt;
     &lt;/div&gt;
  &lt;/div&gt; 
  
  &lt;script type="text/javascript"&gt;
  var lastResults = [];
  
  $("#tags").select2({
      multiple: true,
      placeholder: "Please enter tags",
      tokenSeparators: [","],
      initSelection : function (element, callback) {
          var data = [];
          $(element.val().split(",")).each(function () {
              data.push({id: this, text: this});
          });
          callback(data);
      },
      ajax: {
          multiple: true,
          url: "fetch.php",
          dataType: "json",
          type: "POST",
        data: function (params) {
              return {
                  q: params.term // search term
              };
              },
          results: function (data) {
              lastResults = data;
              return data;
          }
      },
      createSearchChoice: function (term) {
          var text = term + (lastResults.some(function(r) { return r.text == term }) ? "" : " (new)");
          return { id: term, text: text };
      },
  });
  
  $('#tags').on("change", function(e){
      if (e.added) {
          if (/ \(new\)$/.test(e.added.text)) {
             var response = confirm("Do you want to add the new tag "+e.added.id+"?");
             if (response == true) {
                alert("Will now send new tag to server: " + e.added.id);
                /*
                 $.ajax({
                     type: "POST",
                     url: '/someurl&amp;action=addTag',
                     data: {id: e.added.id, action: add},    
                     error: function () {
                        alert("error");
                     }
                  });
                 */
             } else {
                  console.log("Removing the tag");
                  var selectedTags = $("#tags").select2("val");
                  var index = selectedTags.indexOf(e.added.id);
                  selectedTags.splice(index,1);
                  if (selectedTags.length == 0) {
                      $("#tags").select2("val","");
                  } else {
                      $("#tags").select2("val",selectedTags);
                  }
             }
          }
      }
  });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>fetch.php</strong></p>
  
  <p>i checked fetch.php and it is working fine. It is returning the data.</p>
  
  <pre><code>&lt;?php 
      require('db.php');
  
      $search = strip_tags(trim($_GET['q'])); 
      $query = $mysqli-&gt;prepare("SELECT tid,tag FROM tag WHERE tag LIKE :search LIMIT 4");
  
      $query-&gt;execute(array(':search'=&gt;"%".$search."%"));
  
      $list = $query-&gt;fetchall(PDO::FETCH_ASSOC);
  
      if(count($list) &gt; 0){
         foreach ($list as $key =&gt; $value) {
          $data[] = array('id' =&gt; $value['tid'], 'text' =&gt; $value['tag']);                
         } 
      } else {
         $data[] = array('id' =&gt; '0', 'text' =&gt; 'No Products Found');
      }
  
      echo json_encode($data);
  
      ?&gt;
  </code></pre>
  
  <p>I am trying to create tagging and it will check tag in database. 
  if tag not found then user can create new tag and it will save in database and show in user user selection.</p>
  
  <p>At the moment i am not yet created the page to save the tags in database.
  <strong>I tried using select2 version 3.5 and 4.0.1 as well</strong>. </p>
  
  <p>This is first time is i am trying <strong>select2</strong> plugin. So, please ignore if i did silly mistakes. I apologies for that.</p>
  
  <p>Thanks for your time.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I checked in firebug and found data fetch.php didn't get any value from input box. it looks like issue in Ajax. Because it is not sending q value. </p>