Guest User

Untitled

a guest
Feb 6th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var parsedJson;
  2.     new autoComplete({
  3.        selector: 'input[name="search"]',
  4.         minChars: 3,
  5.         source: function (term, response) {
  6.            console.log(term);
  7.            $.ajax({
  8.                type: 'POST',
  9.                url: '/mySql.php',
  10.                data: {inputText: term},
  11.                success: function (data) {
  12.                    console.log(data);
  13.                    var arr ;
  14.                    parsedJson = JSON.parse(data);
  15.  
  16.                    if (parsedJson.length !== 0) {
  17.                        arr= new Array(parsedJson.length);
  18.                        console.log(parsedJson);
  19.                        parsedJson.forEach(function (value, i) {
  20.                            arr[i] = new Array(3);
  21.                            arr[i][0] = value.search_description;
  22.                            arr[i][1] = value.img_link;
  23.                            arr[i][2] = value.link;
  24.                        });
  25.                    }else{
  26.                         arr=new Array(1);
  27.                         arr[0] = new Array(3);
  28.                         arr[0][0] = "Nie znaleziono";
  29.                         arr[0][1] = "https://www.healthvitalize.com/img/page-not-found.png";
  30.                         arr[0][2] = "Nic";
  31.                         console.log(arr);
  32.                    }
  33.                    response(arr);
  34.  
  35.                }
  36.            })
  37.         },
  38.         renderItem: function (item, search) {
  39.             search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  40.             var re = new RegExp("(" + search.split(' ').join('|') + ")", "gi");
  41.             return '<div data-lang="'+item[2]+'" class="autocomplete-suggestion" data-val="' + item[0] + '">' +
  42.                 '<img src="http://motozone.usermd.net/'+item[1]+'">'
  43.                 + item[0].replace(re, "<b>$1</b>") + '</div>';
  44.         },
  45.         onSelect: function (e, term, item) {
  46.            alert(item.getAttribute('data-lang'));
  47.             window.location.replace("http://motozone.usermd.net/"+item.getAttribute('data-lang'));
  48.         }
  49.     });
Advertisement
Add Comment
Please, Sign In to add comment