var search_loop = (str)=>{ setTimeout(()=>{ var new_str = $('#search').val(); if(new_str == str || new_str == ''){ if(new_str == ''){ $('#search_area').html('') } search_loop(new_str); } else { $.get('/search', {q: new_str}).done((data)=>{ $('#search_area').html('') data.forEach((n)=>{ $('#search_area').append( $('

').html( $('').attr({href: "/"+n[0]}).text(n[0]) ).append( $('').addClass('lightgray').html("  "+n[3]) ) ); }); search_loop(new_str); }).fail(()=>{ $('#search_area').html('') seach_loop(new_str) }); } }, 200); } $(()=>{ search_loop('') });