Uploaded image for project: 'Observium'
  1. Observium
  2. OBS-982

Ajax Search bar timeout before posting request

Details

    • Improvement
    • Resolution: Fixed
    • Major
    • None
    • None
    • Web Interface
    • None

    Description

      Our installation is getting quite large and the ajax search bar is close to unusable. I've patched our installation to wait for the user to stop typing before firing off a new ajax_search.php request which has helped nicely.

      I am by no means a programmer so please excuse the dodgy code. But this gets the idea across:

      [root@observium html]# svn -r HEAD diff ./includes/navbar.inc.php
      Index: includes/navbar.inc.php
      ===================================================================
      — includes/navbar.inc.php (revision 5757)
      +++ includes/navbar.inc.php (working copy)
      @@ -465,7 +465,7 @@
      <ul class="nav pull-right">
      <li class="dropdown hidden-xs">
      <form id="searchform" class="navbar-search" action="#" style="margin-left: 5px; margin-right: 10px; margin-top: 5px; margin-bottom: -5px;">

      • <input style="width: 100px;" onkeyup="lookup(this.value);" onblur="$('#suggestions').fadeOut()" type="text" value="" class="dropdown-toggle" placeholder="Search" />
        + <input style="width: 100px;" onkeyup="lookupwait(this.value);" onblur="$('#suggestions').fadeOut()" type="text" value="" class="dropdown-toggle" placeholder="Search" />
        </form>
        <div id="suggestions" class="typeahead dropdown-menu"></div>
        </li>
        @@ -580,7 +580,24 @@
        </header>

      <script type="text/javascript">
      -
      +key_count_global = 0;
      +function lookupwait(inputString){
      + if (inputString.length == 0)

      { + $('#suggestions').fadeOut(); + }

      else

      { + key_count_global++; + setTimeout("searchwait("+key_count_global+",\""+inputString+"\")", 400); + }

      +}
      +function searchwait(key_count,inputString){
      + if(key_count == key_count_global) {
      + $.post("ajax_search.php",

      {queryString: ""+inputString+""}

      , function(data)

      { // Do an AJAX call + $('#suggestions').fadeIn(); // Show the suggestions box + $('#suggestions').html(data); // Fill the suggestions box + }

      );
      +
      + }
      +}
      function lookup(inputString) {
      if (inputString.length == 0) {
      $('#suggestions').fadeOut(); // Hide the suggestions box

      Attachments

        Activity

          [OBS-982] Ajax Search bar timeout before posting request

          Fixed in r6115.

          landy Mike Stupalov added a comment - Fixed in r6115.

          Apologies for the crap formatting.

          davelindon Dave Lindon added a comment - Apologies for the crap formatting.

          People

            landy Mike Stupalov
            davelindon Dave Lindon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: