title: How to avoid multiple ajax call from the Jquery Autocomplete ? Using Cache
body: <p>I am using jquery <code>automcomplete</code> with the <code>Ajax</code> call but what i want is if <code>part</code> is present in the <code>json</code> data fetched by the   ajax on first call then i want to return that data as it is without giving the ajax call i have tried it as below </p>
  
  <pre><code>  function SearchText() {
          var cache = {};
          $("#txtItem").autocomplete({
              source: function (request, response) {
                  var term = request.term;
                  $.each(cache, function (index, value) {
                      $.each(value, function (index, value) {
                          if (value.indexOf(term) &gt;= 0) {
                              response(cache[term]);
                              return;
                          }
                      });
                  });
                  cache = {};
                  $.ajax({
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      url: "JobTagPricing.aspx/GetAutoCompleteData",
                      data: "{'item':'" + document.getElementById('txtItem').value + "'}",
                      dataType: "json",
                      success: function (data) {
                          cache[term] = data.d;
                          response(data.d);
                      },
                      error: function (result) {
                          alert("Error");
                      }
                  });
              },
              minLength: 3
          });
      }
  </code></pre>
  
  <p>but even if it finds the matching <code>term</code> in the array then also it generates the ajax call.
  I m stuck here for 3 hrs now any help would be great. I have tried <code>maxCacheLength</code> but it is also not working.</p>