javascript - Jquery select2 send/retrieve data -


hi there working jquery select2-plugin:

http://ivaynberg.github.io/select2/

the basic usage:

    <select style="width:300px" id="source">         <optgroup label="alaskan/hawaiian time zone">             <option value="ak">alaska</option>             <option value="hi">hawaii</option>         </optgroup>         <optgroup label="pacific time zone">             <option value="ca">california</option>             <option value="nv">nevada</option>             <option value="or">oregon</option>             <option value="wa">washington</option>         </optgroup>     </select>  $(document).ready(function () {     $("#source").select2({         placeholder: "select state",         allowclear: true     }); });  

works perfectly, know how continue when need "loading remote data", url should send data php-file:

include "storescripts/connect_to_mysql.php";  $data = trim(strip_tags($_get['data'])); // this?  if(!empty($data) && isset($data) && strlen($data) != 0) {     $stmt = $dbh->prepare('select id,product `table` `product` :keyword');     $keyword = "%".$data."%";     $stmt->bindparam(':keyword', $keyword, pdo::param_str);     $stmt->execute();        while ($user = $stmt->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" => "you forgot type..." , "result" => 0)); } echo json_encode($user_set);  

anybody know´s how build jquery/ajax process? tried example code website, doesnt work, me request?

greetings!!

example of ajax call:

        $('#dropdown_users').select2({              placeholder: "search user",              minimuminputlength: 3,              multiple: false,          ajax: {              url: "/ingeb/api_v1/users",              datatype: 'json',              quietmillis: 100,              data: function (term, page) {                 return {                     q: term,                      page_limit: 10                  };             },             results: function (data, page) {                     return {results: data};                     }                 }             });  

the format in php returns values should in following format:

[{"id":2,"text":"kim gysen"}] 

the html follows:

<input type="hidden" id="dropdown_users" /> 

set input type hidden.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -