Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var parsedJson;
- new autoComplete({
- selector: 'input[name="search"]',
- minChars: 3,
- source: function (term, response) {
- console.log(term);
- $.ajax({
- type: 'POST',
- url: '/mySql.php',
- data: {inputText: term},
- success: function (data) {
- console.log(data);
- var arr ;
- parsedJson = JSON.parse(data);
- if (parsedJson.length !== 0) {
- arr= new Array(parsedJson.length);
- console.log(parsedJson);
- parsedJson.forEach(function (value, i) {
- arr[i] = new Array(3);
- arr[i][0] = value.search_description;
- arr[i][1] = value.img_link;
- arr[i][2] = value.link;
- });
- }else{
- arr=new Array(1);
- arr[0] = new Array(3);
- arr[0][0] = "Nie znaleziono";
- arr[0][1] = "https://www.healthvitalize.com/img/page-not-found.png";
- arr[0][2] = "Nic";
- console.log(arr);
- }
- response(arr);
- }
- })
- },
- renderItem: function (item, search) {
- search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
- var re = new RegExp("(" + search.split(' ').join('|') + ")", "gi");
- return '<div data-lang="'+item[2]+'" class="autocomplete-suggestion" data-val="' + item[0] + '">' +
- '<img src="http://motozone.usermd.net/'+item[1]+'">'
- + item[0].replace(re, "<b>$1</b>") + '</div>';
- },
- onSelect: function (e, term, item) {
- alert(item.getAttribute('data-lang'));
- window.location.replace("http://motozone.usermd.net/"+item.getAttribute('data-lang'));
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment