cannot call methods on dialog prior to initialization
I'm receiving this error in the console log.
- jquery-1.12.1.min.js:2 Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'destroy'
- at Function.error (jquery-1.12.1.min.js:2)
- at HTMLDivElement.<anonymous> (jquery-ui-1.12.1.min.js:6)
- at Function.each (jquery-1.12.1.min.js:2)
- at n.fn.init.each (jquery-1.12.1.min.js:2)
- at n.fn.init.t.fn.<computed> [as dialog] (jquery-ui-1.12.1.min.js:6)
- at HTMLDivElement.OK (new_appointment.php:901)
- at HTMLButtonElement.<anonymous> (jquery-ui-1.12.1.min.js:11)
- at HTMLButtonElement.dispatch (jquery-1.12.1.min.js:3)
- at HTMLButtonElement.r.handle (jquery-1.12.1.min.js:3)
- error @ jquery-1.12.1.min.js:2
- (anonymous) @ jquery-ui-1.12.1.min.js:6
- each @ jquery-1.12.1.min.js:2
- each @ jquery-1.12.1.min.js:2
- t.fn.<computed> @ jquery-ui-1.12.1.min.js:6
- OK @ new_appointment.php:901
- (anonymous) @ jquery-ui-1.12.1.min.js:11
- dispatch @ jquery-1.12.1.min.js:3
- 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
- "OK":function(){
- $("#close").dialog('destroy');
- //put excuse dialog here
- if(closeFull){
- $('#cancelReason').dialog({
- modal:true,
- draggable:false,
- width:370,
- resizable:false,
- buttons:{
- "Cancel":function(){
- document.cancelForm.reset();
- $("#cancelReason").dialog('destroy');
- },
- "OK":function(){
- var rea = $("#reason").val();
- $("#cancel_reason").val(rea);
- //alert($("#cancel_reason").val());
- $.post("close.php?action=closed",$("#newappointmentform").serialize(),function(data){
- //debug
- //alert(data);
- },"text");
- $.ajax({
- type:'POST',
- cache:false,
- url:'query.php',
- data:{date:selectedDate,id:appointment_id},
- success:showSched
- });
- $("#cancelReason").dialog('destroy');
- document.cancelForm.reset();
- }
- }
- });
- }
- else
- {
- $.post("close.php?action=closed",$("#newappointmentform").serialize(),function(data)
- {
- //debug
- //alert(data);
- },"text");
- document.newappointmentform.reset();
- $("#formWindow").dialog('destroy');
- }
- }