title: Ajax Div Refreshing Too Fast
body: <p>I have a form that posts to a script via ajax, the script inserts the form data into a database and using ajax i the refresh the div on the original page which then shows the form as well as a list of records in the database (from the form input)</p>
  
  <p>I hope that makes sense. </p>
  
  <p>My issue is that sometimes, maybe 1 time in 20, the div refreshes too quickly and doesn't pick up on the new data if i refresh the page its there and if i submit a new record both records are then in the list.</p>
  
  <p>I guess i just need to delay the refreshing but i don't know how.</p>
  
  <p>thanks,</p>
  
  <p>php</p>
  
  <pre><code>echo '&lt;div id="cuttingListDiv"&gt;';
  $sql = "SELECT * FROM `cuttingList` WHERE jobRef = '".$_SESSION["jobRef"]."' ORDER BY pieceMaterialName, pieceThickness ASC";
  $results = $dbconn-&gt;query($sql);
  if ($results-&gt;num_rows &gt; 0) {
      echo '&lt;h3&gt;Cutting List:&lt;/h3&gt;';
      echo '&lt;div align="center"&gt;';
      while($row = $results-&gt;fetch_assoc()) {
          echo '&lt;br /&gt;';
          echo '&lt;div class="row"&gt;';
          echo '&lt;div class="col" align="center"&gt;';
          echo '&lt;h5&gt;'.$row["pieceMaterialName"] . ' - ' . $row["pieceLength"] . '&amp;nbsp;x&amp;nbsp' . $row["pieceWidth"] . '&amp;nbsp;x&amp;nbsp' . $row["pieceThickness"] . 'mm&lt;/h5&gt;';
          echo '&lt;br /&gt;';
          echo '&lt;/div&gt;';
          echo '&lt;/div&gt;';
      }
      echo '&lt;/div&gt;';
  }
  echo '&lt;/div&gt;';
  </code></pre>
  
  <p>ajax script</p>
  
  <pre><code>session_start();
  include '_script_sqlConnection.php';
  
  $pieceLength = strip_tags($_POST['pieceLength']);
  $pieceWidth = strip_tags($_POST['pieceWidth']);
  $thickness = strip_tags($_POST['thickness']);
  $material = strip_tags($_POST['material']);
  $materialName = strip_tags($_POST['materialName']);
  $sheetID = strip_tags($_POST['sheetID']);
  
  // Swap width &amp; length id width bigger
  if ($pieceWidth &gt; $pieceLength) {
      $tmpDimm = $pieceLength;
      $pieceLength = $pieceWidth;
      $pieceWidth = $tmpDimm;
  }
  
  $sql = "INSERT INTO `cuttingList`(`orderRef`, `pieceMaterialName`, `pieceThickness`, `pieceLength`, `pieceWidth`, `sheetID`, `pieceWeight`, `qty`) VALUES ('".$_SESSION["quoteRef"]."', '".$materialName."', '".$thickness."', '".$pieceLength."', '".$pieceWidth."', '".$sheetID."', '".$pieceWeight."', '1')";
  if ($dbconn-&gt;query($sql) === FALSE) {
      echo "Error Adding Pieces To Cut List.&lt;br /&gt;";
  }
  </code></pre>
  
  <p>javascript</p>
  
  <pre><code>$("#cuttingListForm").submit(function(){
      $.ajax({
          type: "POST",
          url: "_script_ajax_addToCuttingList.php",
          data: $('form.cuttingListForm').serialize(),
          success: function() {
              $("#cuttingListDiv").load(location.href + " #cuttingListDiv");
          }
      }); 
  });
  </code></pre>