Advertisement
SipoComp

jQuery Code

Aug 21st, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.             $(function() {
  3.                 var queries = [];
  4.                 $("#searchBox").autocomplete({
  5.                     source: function(request, response) {
  6.                         var resp = [{
  7.                             label:"חיפוש חופשי: "  + term,
  8.                             value: term,
  9.                             url: location.protocol + '//' + location.host + "/?s=" + request.term
  10.                         }];
  11.                         var q = $.ajax({
  12.                             url: "http://hebrew-academy.org.il/wp-admin/admin-ajax.php",
  13.                             dataType: "json",
  14.                             data: {
  15.                                 action: 'autocompleteCallback',
  16.                                 term: request.term
  17.                             },
  18.                             success: function(data) {
  19.                                 console.log(typeof(data));
  20.                                 var d = $.map(data.results, function(item){
  21.                                     var title = $("<div />").html(item.title).text();
  22.                                     return {
  23.                                         label: title,
  24.                                         url: item.url
  25.                                     }
  26.                                 });
  27.                                 Array.prototype.push.apply(resp, d);
  28.                             },
  29.                             error: function(jqXHR, textStatus, errorThrown) {
  30.                                 console.log(jqXHR, textStatus, errorThrown);
  31.                             }
  32.                         });
  33.                         q.then(function(){
  34.                             queries.shift();
  35.                             response(resp);
  36.                         });
  37.                         response(resp);
  38.                     }
  39.                 }) 
  40.             });
  41.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement