Bootstrap Modal JS Uncatch TypeError: undefined 不是函数

Bootstrap Modal JS Uncaught TypeError: undefined is not a function

本文关键字:undefined 函数 TypeError Modal JS Uncatch Bootstrap      更新时间:2023-09-26

我有一个模式,我试图使用 javascript 调用它,但是当该代码运行时,我从控制台收到此错误:

Uncaught TypeError: undefined is not a function

看过类似的问题,但没有一个对我有用。 我的标题如下所示:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>

模式将使用 AJAX 通过单击按钮来填充。 模态的 html 如下所示:

<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div id="slotedit"></div>
        </div>
    </div>
</div>

javascript看起来像这样:

function getEdit(slotID) {
    var xmlhttp = jQuery.noConflict();
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            //Change table element
            document.getElementById("slotedit").innerHTML=xmlhttp.responseText;
            $('#edit').modal('show');
        }        
    }
    xmlhttp.open("POST","getEditData.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("slotID=" + slotID);
}

这让我有点难倒,但是标头中js脚本的顺序似乎没有改变任何东西,并且使用该方法在另一个模态上调用模态也不起作用(表明AJAX是可以的)。

谢谢

编辑: $('#edit')...无法修复它:(

我猜你在('#edit')之前错过了'$'.

应该是$('#edit').modal('show');

另外,为什么不使用jQuery方便的$.ajax方法,$.post,因为你无论如何都在使用jquery?

function getEdit(id) {
  $.post('getEditData.php', { slotID: id }, function(data) {
    $('#slotedit').html(data);
    $('#edit').modal('show');
  });
}

而且,老实说,为什么要担心IE5和IE6;IE6 在全球的使用率低于 1%