javascript - Ajax live search not working on touchscreen phones -


this question has answer here:

i have implemented ajax live search on website.it work browsers when comes touchscreen doesn't show results.i think touch event not being detected code upon several searching on net have no clue do.here code , appreciated

        $(document).ready(function () {          $("#search").keyup(function (e){              var inp = string.fromcharcode(e.keycode);              if (/[a-za-z0-9-_ ]/.test(inp)) {                  $.ajax({                      url: '/search.php',                      type: 'post',                      data: "keyword=" + $(this).val(),                      success: function (data) {                          data = $.parsejson(data);                          if (data['response'] == true) {                              $("#search_results").html(data['html']).show();                          } else {                              alert("please try again.");                          }                      }                  });              }          });            function hide_search_results(e) {              var container = $("#search_results");              if (!container.is(e.target) && container.has(e.target).length === 0) {                  window.displayboxindex = -1;                  container.hide();              }          }            $(document).mouseup(function (e) {              hide_search_results(e);          });      }); 

i believe need touchend event make script supporting touch screens.

try use 2 events .on() instead of .keyup().

$('#search').on('touchend keyup', function(e) {   ... }); 

as alternative can use input event instead of touchend.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -