the dropdown is detected."); } }); $("#query").keyup(function () { refreshDataSearch("#query"); }); $("#query2").keyup(function () { refreshDataSearch("#query2"); }) }); var lock; lock = false; function setPosition(field) { if ($(document).width() > 430) { marginleft = $(document).width() / 3.15; marginleft = parseInt(marginleft) * -1; $('#resultSearch').css('width', '64%'); } else { marginleft = $(document).width() / 2.2; marginleft = parseInt(marginleft) * -1; $('#resultSearch').css('width', '90%'); } var position = $(field).offset(); var newpos = position.top + $(field).height() + 10; $('#resultSearch').css('top', newpos + 'px'); $('#resultSearch').css('margin-left', marginleft + 'px'); } function refreshDataSearch(field) { //console.log("refreshing..."); // /* if (resetpage == true) { $('#page').val('1'); loading(true); $('#content').html(""); } else { loading(false); } * */ if($(document).width() > 430){ var mobile='0'; }else{ var mobile='1'; } if (field == "#query") { $("#query2").val($(field).val()); } else { $("#query").val($(field).val()); } if (lock == false) { lastSearch = $(field).val(); setPosition(field); $("#resultSearch").show(100); lock = true; var url = "/getJsonSearch.php?mobile="+mobile+"&" + $('#formsearch').serialize(); //console.log(url); $.ajax({ url: url, dataType: 'json' }).done(function (data, textStatus, jqXHR) { showDataSearch(data); if (lastSearch != $(field).val()) { refreshDataSearch(field); } }).fail(function (jqXHR, textStatus, errorThrown) { console.log("FAIL " + errorThrown); lock = false; }); } } function showDataSearch(data) { // console.log(data); lock = false; $("#resultSearch").html(data.html); }