ajax - TypeError: $(…).modal is not a function in yii1 -
i have button, when clicked on modal popsup. enter data , submit form using ajax. after data submitted wanted modal close. tried (relevent code )
$form=$this->beginwidget('cactiveform', array(         'id'=>'employee-task-form',         'enableajaxvalidation'=>true,         'clientoptions'=>array(             'validateonsubmit'=>true,             'aftervalidate'=>'js:function(form,data,haserror){                         if(!haserror){                                 $.ajax({                                         "type":"post",                                         "url":"'.chtml::normalizeurl(array('employeetasks/create','ajax')).'",                                         "data":form.serialize(),                                         "success":function(){                                         toastr.success("saved successfully.", "success");                                          $("#ajaxmodal").modal("close");                                              // $("#ajaxmodal").modal("hide");                                          },                                          });                                 }                         }'         ), ));    <script type="text/javascript"> jquery('document').ready(function($){ jquery("body").on("click", ".popup", function (e) {     var url = $(this).attr("href");     $("#ajaxmodal").find(".modal-body").load(url + "?ajax=1", false, function (responsetext, status, req)     {         if (status != "error") {             $("#ajaxmodal").modal({backdrop: "static", keyboard: true});         }         else             toastr.error("failed load", "loading failed");     });     e.preventdefault(); }); }); </script> data geting saved ie,ajax function working toaster, modal not closing , error uncaught typeerror: $(...).modal not function.
edit
i posted same question in yiiframework forum link
and saying cannot close modal because the modal() function doesn't exist in jquery so?
i able hide modal using code $("#ajaxmodal").hide(); background remains in grey colour(same colour when modal poped up)
edit
hi, tried
  $("#ajaxmodal").hide();                $("body").removeclass("modal-open");                 $(".modal-backdrop").remove();  then close modal next time when click on button modal not pop ing up.
i found reason error. calling modal before bootstrap.min.js. reason why getting  typeerror: $(…).modal not function error.
The $(…).modal is not a function is usually caused because scripts are loaded in the wrong order . The browser will execute the scripts in the order it finds them. If in a script you attempt to access an element that hasn't been reached yet then you will get an error. Make sure that you don't have a script above one that it requires.
ReplyDeleteMultiple jQuery instances
Sometimes this warning may also be shown if jQuery is declared more than once in your code. The second jQuery declaration prevents bootstrap.js from working correctly. The problem is due to having jQuery instances more than one time. Take care if you are using many files with multiples instance of jQuery. Just leave one instance of jQuery and your code will work.