title: Unstable search engine in ajax
body: <p>I come to you because I am optimizing my website that I created during my study hours, and I notice that I have a "ajax call error" error that sometimes appears on my search engine.
  I’m still starting in Ajax, and I don’t understand why this is happening:/</p>
  
  <p>Here is the code:</p>
  
  <pre><code>    //Timer - Une seule requête après saisie
      var attente = function(){
          var timer = 1000;
          return function(callback, ms){
          clearTimeout (timer);
          timer = setTimeout(callback, ms);
          };
      }();
  
      $( document ).ready(function() {
          $("#autocompl").keyup(function(){
              var profileSearch = $(this).val();
              if ( profileSearch.length &gt;= 2 ) {
                  attente(function(){
                      $.ajax({
                          type: "POST",
                          url: "/profile/search/ajax/" + profileSearch,
                          dataType: 'json',
                          timeout: 10000,
                          // Fonction TIMER For no AJAX CALL ERROR
                          success: function(response){
                              var profileSearchs = response;
                              if (profileSearchs.length == 0) {
                                  $('#result-auto-solut').html('No result');
                              } else {
                                  html = "&lt;ul id='solut' class='auto-complete-list'&gt;";
                                  for (var i = 0; i &lt; profileSearchs.length; i++) {
                                      html += "&lt;li&gt;&lt;a href='/structure/"+profileSearchs[i].id+"'&gt;&lt;b&gt;"+ profileSearchs[i].name + "&lt;/b&gt;  &lt;small&gt;&lt;i&gt;"+profileSearchs[i].city+" "+ profileSearchs[i].postal+"&lt;/i&gt;&lt;/small&gt;&lt;/a&gt;&lt;/li&gt;";
                                  }
                                  html += "&lt;/ul&gt;";
                                  $('#result-auto-solut').html(html);
                                  $('#result-auto-solut').find('li').on('click', function () {
                                      $('#result-auto-solut').html('');
                                  });
                              }
                          },
                          error: function() {
                              $('#result-auto-solut').text('Ajax call error');
                          }
                      });
                  }, 1000 );
              } else {
                  $('#result-auto-solut').html('');
              }
          });
      });
  </code></pre>
  
  <p>I thank you in advance, and will answer you as soon as possible</p>