Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////
- ////////////////// Javascript
- //////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- var availableTags , array , val , key;
- var ar = [];
- $(function() {
- $.ajax({
- url: 'autocomplete',
- type: 'GET',
- dataType: 'json',
- data:"",
- })
- .done(function(data) {
- availableTags = data;
- console.log("get data success");
- console.log(availableTags);
- $.each(availableTags, function(key, val) {
- var value = val['name'];
- ar.push(value);
- });
- console.log(ar);
- })
- .fail(function() {
- console.log("error");
- })
- .always(function() {
- //console.log("complete");
- });
- //end ajax
- ///////////////////////////
- $( "#artist" ).autocomplete({
- source: ar
- });
- });
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////
- ////////////////// Controller
- //////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function getArtistAutocomplete(){
- $artist = DB::select('select name from artist');
- foreach ($artist as $query){
- $results[] = [ 'name' => $query->name];
- }
- $response = Response::json($results);
- /*$response = Response::json_decode($artist);
- $response->header('Content-Type', 'application/json');
- $response->header('charset', 'utf-8');
- */
- return $response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement