title: using jquery ajax to load info from database
body: <h2>Problem</h2>
  
  <p>I tried using the following</p>
  
  <pre><code>// Start method 1
  
  var grbData = $.ajax({
          type : "GET",
          url : "http://grb.sonoma.edu:81/getgrbs.php",
          data : "start=0&amp;perPage=3"}).responseText;
  
  $("#ajaxDiv").html(grbData);
  
  // End method 1
  
  // Start method 2
  
  $.get("getgrbs.php", { start : 0, perPage : 3},
          function(data) {
                $("#tst").html(data);
          }, "html");
  
  // End method 2
  </code></pre>
  
  <p>on this page: <a href="http://grb.sonoma.edu:81/paging.php" rel="nofollow noreferrer">http://grb.sonoma.edu:81/paging.php</a> to load data from a database. Method 1 only appears to work in IE8 but only after the page is refreshed. When the page is first loaded I get a "The data necessary to complete this operation is not yet available." error.</p>
  
  <p>The reason I prefer Method 1 is because it gives me access to individual rows in the table. E.g. Each row has a class, "burst." I am using </p>
  
  <pre><code>$(".burst").click(function() {
          $(".burst").css("background-color", "");
          $(this).css("background-color", "yellow");
      });
  </code></pre>
  
  <p>to change the color of the selected row when clicked. This only appears to work with Method 1 and not method 2.</p>
  
  <p>All of the above code in encapsulated in $(document).ready(). I have tried </p>
  
  <pre><code>$("#ajaxDiv").load("getgrbs.php", { start : 0, perPage : 3});
  </code></pre>
  
  <p>but I get results similar to Method 2.</p>
  
  <p>How can I get the click function to work with Method 2 or get Method 1 to work on all browsers without refresh? Thanks for any help I can get for this.</p>
  
  <p>I need to do this in ajax (tried ajax without jquery and no luck there either) since there will be other things on the page that will not change as the user pages through the data.</p>
  
  <h2>Addendum to solution (better solution in answer)</h2>
  
  <p>After successfully using "success" I noticed that the ability to click on row and have the bg color change was gone. So I did the following, which appears to work. Not sure it if is the best way.</p>
  
  <pre><code>var grbData = $.ajax({
      type : "GET",
      url : "http://grb.sonoma.edu:81/getgrbs.php",
      data : "start=0&amp;perPage=3",
      dataType : 'html',
      success: function (data) {
              $("#ajaxDiv").replaceWith(data);
              startInteraction();
          }
  });
  
  function startInteraction() {
      $(".burst").click(function() {
          $(".burst").css("background-color", "");
          $(this).css("background-color", "yellow");
      });
  }
  </code></pre>