title: Jquery select2 send/retrieve data
body: <p>Hi there i am working with the jquery select2-plugin:</p>
  
  <p><a href="http://ivaynberg.github.io/select2/" rel="nofollow">http://ivaynberg.github.io/select2/</a></p>
  
  <p>The basic usage:</p>
  
  <pre><code>    &lt;select style="width:300px" id="source"&gt;
          &lt;optgroup label="Alaskan/Hawaiian Time Zone"&gt;
              &lt;option value="AK"&gt;Alaska&lt;/option&gt;
              &lt;option value="HI"&gt;Hawaii&lt;/option&gt;
          &lt;/optgroup&gt;
          &lt;optgroup label="Pacific Time Zone"&gt;
              &lt;option value="CA"&gt;California&lt;/option&gt;
              &lt;option value="NV"&gt;Nevada&lt;/option&gt;
              &lt;option value="OR"&gt;Oregon&lt;/option&gt;
              &lt;option value="WA"&gt;Washington&lt;/option&gt;
          &lt;/optgroup&gt;
      &lt;/select&gt;
  
  $(document).ready(function () {
      $("#source").select2({
          placeholder: "Select a State",
          allowClear: true
      });
  }); 
  </code></pre>
  
  <p>Works perfectly,
  but does anybody know how to continue when i need "Loading Remote Data", the url should send data to php-file:</p>
  
  <pre><code>include "storescripts/connect_to_mysql.php";
  
  $data = trim(strip_tags($_GET['data'])); // Like this?
  
  if(!empty($data) &amp;&amp; isset($data) &amp;&amp; strlen($data) != 0) {
      $stmt = $dbh-&gt;prepare('SELECT id,product FROM `table` WHERE `product` LIKE :keyword');
      $keyword = "%".$data."%";
      $stmt-&gt;bindParam(':keyword', $keyword, PDO::PARAM_STR);
      $stmt-&gt;execute();   
      while ($user = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
          $user['item']=htmlentities(stripslashes($user['product']));
          $user['id']=$user['id'];
          $user_set[] = $user;
      }
      echo json_encode($user_set);
  } else { 
      echo json_encode(array("error" =&gt; "You forgot to type..." , "result" =&gt; 0));
  }
  echo json_encode($user_set); 
  </code></pre>
  
  <p>Anybody know´s how to build the jquery/ajax for this process?
  I tried example code from website, but doesnt work, anybody could help me with this request?</p>
  
  <p>Greetings!!</p>