title: Why does this AJAX call take so long?
body: <p>This takes between 2-4 seconds normally, which seems like far too long for the work it is doing. 
  Here is the AJAX:</p>
  
  <pre><code>$("#IngTable").html("&lt;center&gt;&lt;img src=../img/loading.gif /&gt;&lt;/center&gt;");
  
      var search = document.getElementById("IngSearch").value;
      var apiLink = "/API/Ingredient/Search?search=" + search;
      $.ajaxSetup({ accepts: "application/json" });
      $.ajax({
          url: apiLink,
          type: "GET",
          success: function(data) {
              var ingredients = JSON.parse(data);
              var htmlIngred = "";
              for (var i = 0; i &lt; ingredients.length; i++) {
                  htmlIngred += "&lt;tbody&gt;&lt;td&gt;&lt;span&gt;" + ingredients[i].Name + "&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;a class='btn btn-success btn-mini' onclick='addIngred(" + ingredients[i].IngredientId + ");'&gt;Add&lt;/a&gt;&lt;/td&gt;&lt;/tbody&gt;";
              }
              document.getElementById("IngTable").innerHTML = htmlIngred;
          },
          error: function (a, b, c) { }
      });
  </code></pre>
  
  <p>And here is the Web API Controller:</p>
  
  <pre><code>    [HttpGet]
      public string IngredientSearch(string search)
      {
          var sw = Stopwatch.StartNew();
          var db = new Glubee.Model.GlubeeEntities();
          var results = db.Ingredients.Where(x =&gt; x.Name.Contains(search)).ToArray();
          sw.Stop();
          return JsonConvert.SerializeObject(results);
      }
  </code></pre>
  
  <p>There is only 16 things in the ingredients table, each being no more than 20 characters long. </p>
  
  <p>Does anyone have any idea where the issue might be in this that makes it take so long?</p>
  
  <p>Edit: Here is my Global.asax.cs page if it is helpful:</p>
  
  <pre><code>public class MvcApplication : System.Web.HttpApplication
  {
      protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
  
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
          BundleConfig.RegisterBundles(BundleTable.Bundles);
      }
  </code></pre>
  
  <p>And here is my RouteConfig:</p>
  
  <pre><code>public class RouteConfig
  {
      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
  
          routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
      }
  }
  </code></pre>