title: Magento jQuery Ajax search issue
body: <p><br />
  I am trying to implement a customize Magento Advanced Search, using jQuery and Ajax.
  <br />
  The search works something like this: 
  <br />
  1) There are 2/3 options to select size <br />
  2) 6 options to narrow down search result <br />
  3) A text box to enter keywords etc<br /></p>
  
  <p>There is no submit button, that means, search starts when user clicks on any size and/or Options or enter more than 3 char in search text box, search starts, an ajax request is sent to server. <br />
  If user clicks on another option or say type in another character, I use to abort previous search using <code>search_request.abort()</code> and set previous search to null.
  <br /><br />When you search for first couple of times, it works fine, search returns result and if no result is found, proper message is displayed.But, after after couple of requests, it starts failing. Like if I click on options in short interval (I mean, search is fired frequently)). Some times, it fails without any reason and sometimes it fails, and when I click on the same option a couple of seconds later, it display the results. 
  <br />Sometimes, when the search fails or there is no result. 
  <br />It displays the incomplete message in result area like: 
  <img src="https://i.stack.imgur.com/a4vuA.png" alt="incomplete no search result">
  Where as it should look like :
  <img src="https://i.stack.imgur.com/usGY5.png" alt="complete no search result"></p>
  
  <p><br />
  Search when it returns result:
  <img src="https://i.stack.imgur.com/lu1F0.png" alt="Search Result">
  Search when it fails 
  <img src="https://i.stack.imgur.com/aiiK1.png" alt="enter image description here">
  <hr />
  <strong><em>My question is:</em></strong><br />
  1) do you think it might be failing because <strong>too many requests are submitted too frequently</strong>? I mean is there something related to <strong>Magento settings</strong>?<br />
  2) What can I do to correct this?</p>
  
  <p><hr />
  Here is the jQuery code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function search(textfield)
  {
      j('#slides').html("&lt;img src='&lt;?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?&gt;skin/frontend/luckybloke/luckybloke/images/ajax-loader.gif' class='no-results-found' style='width:100px !important; padding-top:10px !important;text-align:center;margin-left: 43%;' /&gt;");
      var form = j("#form-validate");
      var action = form.attr("action");
      var fieldAdded = Array();
      var searchData = '';
      var searchVal  = '';
      var sizeSelected = '';
      var searchArray = new Array();
      var searchCtr = 0;
      var tmp     = new Array();        
      if(typeof search_request =='object' &amp;&amp; search_request!=null){
        search_request.abort();          
        search_request = null;
        j('#slides').html("&lt;img src='&lt;?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?&gt;skin/frontend/luckybloke/luckybloke/images/ajax-loader.gif' class='no-results-found' style='width:100px !important; padding-top:10px !important;text-align:center;margin-left: 43%;' /&gt;");
      }
  
      j('.input-search').each(function(index,domEle){
          var eleID = "#"+j(domEle).attr("id");
          var curEle= j(domEle).attr("name");
          fieldAdded.push(curEle.replace('[]',''));
          ////consloe.log(eleID);            
          if((j(eleID).val()!='' || !jQuery.inArray(curEle,fieldAdded))&amp;&amp; eleID!='#name'){
              if(searchVal==''){
                  searchVal=searchVal+j(eleID).val();
              }                
  
  
                  if(searchData==''){
                      searchData = searchData+""+curEle+"="+j(eleID).val();
                  }else{
                      searchData = searchData+"&amp;"+curEle+"="+j(eleID).val();
                  }
                  searchArray[searchCtr] = j(eleID).val();
                  searchCtr++;
              }
              //add description field to search query                
              tmp[curEle] = j(eleID).val();
  
          }
      });
  
  
      if(searchVal==''){
  
      }
      if(j("#name").val()=='brand, style, keyword'){ 
          var val = '';
      }else{
          val = j("#name").val();
      }  
  
      searchData = searchData+"&amp;search_keywords="+val;        
      //toggleFields(sizeSelected, searchArray);
      search_request = j.ajax({
          type:'get',
          url:action,
          data:searchData, 
          cache: false,
          dataType:'html',
          success:searchComplete
      });
      return;
  }
  
  
  function searchComplete(responseText, statusText, xhr, $form)
  {          
      var no_item_msg = 'No product found matching your search criteria.';
      if(statusText=='success'){
              var isFound = responseText.toString().search(new RegExp(/no items found/i)); 
              //alert(isFound+''+responseText.toString());                      
          if((isFound&gt;0 || responseText.length == 0) &amp;&amp; search_request ){             
              j("div#slides").html("&lt;span class='no-results-found'&gt;"+no_item_msg+"&lt;/span&gt;");
          //    j("div#slides").html("&lt;span class='no-results-found'&gt;"+no_item_msg+"&lt;/span&gt;");
              /*j("div#lb-product-list").block({message:no_item_msg});
              setTimeout('j("div#lb-product-list").unblock()', 2000);*/
          }else{           
              var dataToFill = j("div#lb-product-list");      
              var isFound = responseText.toString().search(new RegExp(/JUST_ONE/i));                
              if(isFound&gt;=0){
                  responseText = responseText.replace(/just_one/i,'');
              }else{
                  j.getScript("&lt;?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?&gt;js/carousol.js", function() {});
              }
              dataToFill.html(j(responseText).children());                
              search_request = null;                
          }
          //reset the css attribute's position value, as ui blocking seems to be affecting positioning of elements are unblocking
          j("div#lb-product-list").css("position",'');
          return true;
      }
  }
  &lt;/script&gt;
  </code></pre>