title: Using Ajax Loading with Smart Search field
body: <p>Imagine the Google search bar. When you type something it is Smart Searchable where it gives you possible results while typing. My search bar does that. But then the Search Icon to the right in Google while typing and after hitting enter on an option, I would like the Search Icon to change out to a Loading Gif while it processes?</p>
  
  <p>Can someone share direction on what I'm missing in getting an Ajax Loading gif to be visible while waiting for options and then once chosen showing the Loading gif while waiting to show your result?</p>
  
  <p>Using ASP and jQuery</p>
  
  <p>Here is what I got so far:</p>
  
  <p>This is what it should be before anything is typed in the search box, a magnifying glass:</p>
  
  <pre><code>`
  &lt;img style="background:url(/images/image_giblets_20x.png) no-repeat scroll right -414px transparent" src="images/transparent_100x100.png" width="23px" height="23px" /&gt;
  `
  </code></pre>
  
  <p>Then while typing it is set up to show results of what you might be looking for. And while those results are loading I would like to have a loading icon spin.</p>
  
  <pre><code>`
  &lt;img id="loading_image" src="/images/ajax-loader.gif" alt="Loading..." /&gt;
  `
  </code></pre>
  
  <p>It would then stop and go back to the Magnifying glass and then once you click Enter or select an option and click enter or maybe even just type a search result and click Enter the loading icon would then spin again indicating you to wait while the result is generating.</p>
  
  <p>So currently in HTML/ASP page I have this:</p>
  
  <pre><code>`
  &lt;img style="background:url(/images/image_giblets_20x.png) no-repeat scroll right -414px transparent" src="images/transparent_100x100.png" width="23px" height="23px" /&gt;
  `
  
  `
  &lt;img id="loading_image" src="/images/ajax-loader.gif" alt="Loading..." /&gt;
  `
  </code></pre>
  
  <p>Then I have a JS page that has this:</p>
  
  <pre><code>`
  // Smart Search ajax loader
  $(window).load(function() {
          $('#loading_image').hide();
      });
  `
  </code></pre>
  
  <p>I want to hide the first image and show the second image and once the loading is done to go back to the first image.</p>
  
  <p>Thanks All for the clarity Cheers!!</p>
  
  <p>Here's where I'm at now with it. The images are both still visible side by side:</p>
  
  <p>My ASP:</p>
  
  <pre><code>`
        &lt;div id="smart_search"&gt;
  
          &lt;asp:TextBox ID="searchfield" runat="server" /&gt;
  
          &lt;asp:TextBoxWatermarkExtender ID="TBWE2" runat="server" TargetControlID="searchfield" WatermarkText="Search alpaca, farm and owner names here!" WatermarkCssClass=""/&gt;
          &lt;asp:HiddenField ID="HiddenField1" runat="server"  /&gt;
          &lt;img id="magnifying_glass" style="background:url(/images/image_giblets_20x.png) no-repeat scroll right -414px transparent" src="images/transparent_100x100.png" width="23px" height="23px" /&gt;
                  &lt;img id="loading_image" src="/images/ajax-loader.gif" alt="Loading..." /&gt;
  
        &lt;/div&gt;
  `
  </code></pre>
  
  <p>My JS:</p>
  
  <pre><code>`
  // Smart Search ajax loader
   $("#searchfield").bind("keyup", function(args){
       //check key value 
       $('#magnifying_glass').hide();
       $('#loading_image').show();
       var searchvalue = $("#searchfield").val();
       $.ajax({
           data: "searchvalue=" + searchvalue,
           url: "/getsearchvalue",
           success: function(result){
               $('#loading_image').hide();
               $('#magnifying_glass').show();
               //handle result
           }
              });
  });
  `
  </code></pre>