Strange Dialog .load Loop

Strange Dialog .load Loop

Let me see if I can explain this without a million lines of code to start out with. User selects to add a new part. This then loads a Dialog box with a part search (part-search.php) in it. Part is then searched for. If a no in stock part is found it moves to a (part-add.php). Inside that page is an autocomplete jquery setup. Perfect, everything works great.

Here is the redirect/load in new page script


   $(function() {
    $('#searchbox').empty();
    $('#addbox').load('parts-add.php?pn=<?PHP echo $search; ?>');
    return false;
   });

Say a stock part was found, but nothing they want to use. User can then use a 'skip' button the runs the exact same scenario above with a click function (I'll lost that below). The .load seems to work fine, but it won't stop. Every second or two it empties and reloads the div over and over. Here is the skip code...


   $(function() {
    $('#btnSkip').click(function(e){
     e.preventDefault();
     $('#searchbox').empty();
     $('#addbox').load('parts-add.php?pn=<?PHP echo $search; ?>');
     return false;
    });

Only in this exact scenario does the loop happen. Just in case here below is the auto complete code, because if I remove this code the loop stops. But the autocomplete is a must so we have all the info needed to order a part. Thank you very much for even trying to understand what I am asking for help with.


<script language="javascript">
 $(function() {
  var sourceParts = [
<?PHP
 $list = '';
 $query = $db->query("SELECT DISTINCT(pn) FROM tickets_parts ORDER BY id DESC");
 while ($row = $query->fetch_array()) {
  $qDesc = $db->query("SELECT description,price_unit FROM tickets_parts WHERE pn='$row[0]' ORDER BY id DESC LIMIT 1");
  while ($rDesc = $qDesc->fetch_array()) {
   if (isset($fla)) {
    $list .= ",\r\n";
   }
   $fla = 1;
   
   $list .= "\t\t\t" . '{ value: "' . $row[0] . '", desc: "' . addslashes($rDesc[0]) . '", price: "' . $rDesc[1] . '" }';
  }
 }
 $query->close();
 echo $list;
?>

  ];
  
  $("#pn").autocomplete({
   minLength: 0,
   source: sourceParts,
   focus: function( event, ui ) {
    $( "#pn" ).val( ui.item.value );
    return false;
   },
   select: function( event, ui ) {
    $( "#pn" ).val( ui.item.value );
    $( "#description" ).val( ui.item.desc );
    return false;
   }
  })
  .autocomplete("instance")._renderItem = function( ul, item ) {
   return $( "<li>" )
    .append( "<a>" + item.value + "</a>" )
    .appendTo( ul );
  }
  .autocomplete("widget").insertAfter($("#addbox").parent());
 });
</script>