简体   繁体   English

Bootstrap Modal JS Uncaught TypeError:未定义不是函数

[英]Bootstrap Modal JS Uncaught TypeError: undefined is not a function

I have a modal that I'm trying to call using javascript, but I get this error from the console when that code is being run: 我正在尝试使用javascript调用一个模式,但是在运行该代码时从控制台收到此错误:

Uncaught TypeError: undefined is not a function

I've had a look at similar issues, but none of them have worked for me. 我看过类似的问题,但没有一个对我有用。 My header looks like this: 我的标题看起来像这样:

<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>

The modal is to be filled in using AJAX using a button click. 单击按钮即可使用AJAX填写模态。 The html for the modal looks like this: 模态的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>

And the javascript looks like this: 和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);
}

It's stumped me a bit, but the order of the js script in the header seems to not change anything, and using the method to call the modal on another modal does't work either (suggesting the AJAX is OK). 这让我有些难过,但是标头中js脚本的顺序似乎没有任何变化,并且使用该方法在另一个模式上调用该模式也不起作用(建议AJAX可以)。

Thanks 谢谢

Edit: $('#edit')... doesn't fix it :( 编辑:$('#edit')...不能解决它:(

I guess you are missing '$' before ('#edit') . 我想您在('#edit')之前缺少'$'

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

Also, why not use jQuery's convenience $.ajax method, $.post , since you're using jquery anyway? 另外,为什么不使用jQuery方便的$ .ajax方法$.post ,因为无论如何您都在使用jquery?

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

And, honestly, why worry about IE5 and IE6; 老实说,为什么还要担心IE5和IE6? IE6 has less than 1% usage, globally IE6在全球范围内的使用率不到1%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Uncaught TypeError:对于Bootstrap Modal未定义 - Uncaught TypeError: undefined for Bootstrap Modal Bootstrap - “未捕获的TypeError:undefined不是函数” - Bootstrap - “Uncaught TypeError: undefined is not a function” 模态错误-未捕获的TypeError:undefined不是函数模态 - Modal error - Uncaught TypeError: undefined is not a function modal Bootstrap FullCalendar未捕获的TypeError:undefined不是函数 - Bootstrap FullCalendar Uncaught TypeError: undefined is not a function Bootstrap .dropdown()“Uncaught TypeError:undefined不是函数” - Bootstrap .dropdown() “Uncaught TypeError: undefined is not a function” React.js:未被捕获的TypeError:undefined不是一个函数 - React.js : Uncaught TypeError: undefined is not a function Ember.js:未捕获的TypeError:未定义不是一个函数 - Ember.js: Uncaught TypeError: undefined is not a function 未捕获的TypeError:undefined不是函数 - typeahead.js - Uncaught TypeError: undefined is not a function - typeahead.js 未捕获的TypeError:undefined不是simplePagination.js中的函数 - Uncaught TypeError: undefined is not a function in simplePagination.js Uncaught TypeError:undefined不是函数敲除js - Uncaught TypeError: undefined is not a function knockout js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM