cannot call methods on dialog prior to initialization

cannot call methods on dialog prior to initialization

I'm receiving this error in the console log.
  1. jquery-1.12.1.min.js:2 Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'destroy'
  2.     at Function.error (jquery-1.12.1.min.js:2)
  3.     at HTMLDivElement.<anonymous> (jquery-ui-1.12.1.min.js:6)
  4.     at Function.each (jquery-1.12.1.min.js:2)
  5.     at n.fn.init.each (jquery-1.12.1.min.js:2)
  6.     at n.fn.init.t.fn.<computed> [as dialog] (jquery-ui-1.12.1.min.js:6)
  7.     at HTMLDivElement.OK (new_appointment.php:901)
  8.     at HTMLButtonElement.<anonymous> (jquery-ui-1.12.1.min.js:11)
  9.     at HTMLButtonElement.dispatch (jquery-1.12.1.min.js:3)
  10.     at HTMLButtonElement.r.handle (jquery-1.12.1.min.js:3)
  11. error @ jquery-1.12.1.min.js:2
  12. (anonymous) @ jquery-ui-1.12.1.min.js:6
  13. each @ jquery-1.12.1.min.js:2
  14. each @ jquery-1.12.1.min.js:2
  15. t.fn.<computed> @ jquery-ui-1.12.1.min.js:6
  16. OK @ new_appointment.php:901
  17. (anonymous) @ jquery-ui-1.12.1.min.js:11
  18. dispatch @ jquery-1.12.1.min.js:3
  19. r.handle @ jquery-1.12.1.min.js:3

I searched extensively for an answer and found several people stating, " loading the jquery library on the partial page as well as the main page," caused the error for them.

I checked my pages for this particular webpage and jquery is only loaded once, in my nav.php include file, which is included in the main php page for this particular webpage.

The error only happens when I click a "close" button on a dialog box, in which the item being closed, an appointment form that is not full, has no form data. 
The close function
  1. "OK":function(){
  2.   $("#close").dialog('destroy');
  3.   //put excuse dialog here
  4.   if(closeFull){
  5. $('#cancelReason').dialog({
  6.    modal:true,
  7.    draggable:false,
  8.    width:370,
  9.    resizable:false,
  10.    buttons:{
  11.   "Cancel":function(){
  12. document.cancelForm.reset();
  13. $("#cancelReason").dialog('destroy');
  14.   },
  15.   "OK":function(){
  16. var rea = $("#reason").val();
  17. $("#cancel_reason").val(rea);
  18. //alert($("#cancel_reason").val());
  19. $.post("close.php?action=closed",$("#newappointmentform").serialize(),function(data){
  20. //debug
  21. //alert(data);
  22. },"text");
  23. $.ajax({
  24. type:'POST',
  25. cache:false,
  26. url:'query.php',
  27. data:{date:selectedDate,id:appointment_id},
  28. success:showSched
  29. });
  30. $("#cancelReason").dialog('destroy');
  31. document.cancelForm.reset();
  32.   }
  33.    }
  34. });
  35.   }
  36.   else
  37.   {
  38.   $.post("close.php?action=closed",$("#newappointmentform").serialize(),function(data)
  39. {
  40.    //debug
  41.    //alert(data);
  42. },"text");
  43.   document.newappointmentform.reset();
  44.   $("#formWindow").dialog('destroy');
  45.   }
  46. }