Advertisement
julong

Autocomplete

Aug 4th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //////////////////
  3. ////////////////// Javascript
  4. //////////////////
  5. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6. var availableTags , array , val , key;
  7. var ar = [];
  8. $(function() {
  9. $.ajax({
  10. url: 'autocomplete',
  11. type: 'GET',
  12. dataType: 'json',
  13. data:"",
  14. })
  15. .done(function(data) {
  16. availableTags = data;
  17. console.log("get data success");
  18. console.log(availableTags);
  19. $.each(availableTags, function(key, val) {
  20. var value = val['name'];
  21. ar.push(value);
  22. });
  23. console.log(ar);
  24. })
  25. .fail(function() {
  26. console.log("error");
  27. })
  28. .always(function() {
  29. //console.log("complete");
  30. });
  31. //end ajax
  32. ///////////////////////////
  33. $( "#artist" ).autocomplete({
  34. source: ar
  35. });
  36. });
  37.  
  38.  
  39. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  40. //////////////////
  41. ////////////////// Controller
  42. //////////////////
  43. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  44. public function getArtistAutocomplete(){
  45. $artist = DB::select('select name from artist');
  46. foreach ($artist as $query){
  47. $results[] = [ 'name' => $query->name];
  48. }
  49. $response = Response::json($results);
  50. /*$response = Response::json_decode($artist);
  51. $response->header('Content-Type', 'application/json');
  52. $response->header('charset', 'utf-8');
  53. */
  54. return $response;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement