我的javascript返回此错误:$ .ajax不是函数

不知道出了什么问题,但我从Chrome控制台收到此错误:

jquery-3.2.1.slim.min.js:1244 jQuery.Deferred exception: $.ajax is not a function TypeError: $.ajax is not a function at HTMLDocument. (file:///C:/Users/Adam/Desktop/UseTime/js/example.js:3:7) at j (file:///C:/Users/Adam/Desktop/UseTime/js/jquery-3.2.1.slim.min.js:1193:55) at k (file:///C:/Users/Adam/Desktop/UseTime/js/jquery-3.2.1.slim.min.js:1199:45) undefined r.Deferred.exceptionHook @ jquery-3.2.1.slim.min.js:1244 jquery-3.2.1.slim.min.js:1247 Uncaught TypeError: $.ajax is not a function at HTMLDocument. (example.js:3) at j (jquery-3.2.1.slim.min.js:1193) at k (jquery-3.2.1.slim.min.js:1199) 

从这个JavaScript:

 $(function() { //when the DOM is ready var times; //declare global variable $.ajax({ //set up request beforeSend: function (xhr) { //before requesting data if (xhr.overrideMimeType) { //if supported xhr.overrideMimeType("application/json"); // set MIME to prevent errors } } }); //funciton that collect data from the json file function loadTimetable() { //decalre function $.getJSON('data/example.json') //try to collect json data .done(function (data) { //if succesful times = data; //store in variable }).fail(function () { //if a problem: show message $('#event').html('Sorry! we couldnt load your time table at the moment'); }); } loadTimetable(); //call the function //CLICK ON TEH EVENT TO LOAD A TIME TABLE $('#content').on('click', '#event a', function (e) { //user clicks on place e.preventDefault(); //prevent loading page var loc = this.id.toUpperCase(); //get value of id attr var newContent = ""; for (var i = 0; i < times[loc].length; i++) { // loop through sessions newContent += '
  • ' + times[loc][i].time + ''; newContent += ''; newContent += times[loc][i].title + '
  • '; } $('#sessions').html('
      ' + newContent + '
    '); // Display Time $('#event a.current').removeClass('current'); // update selected link $(this).addClass('current'); $('#details').text(''); }); //CLICK ON A SESSION TO LEAD THE DESCRIPTION $('#content').on('click', '#sessions li a', function (e) { //click on session e.preventDefault(); // prevent loading var fragment = this.href; //title is in href fragment = fragment.replace('#', ' #'); //Add Space before # $('#details').load(fragment); //to load info $('#sessions a.current').removeClass('current'); //update selected }); //CLICK ON PRIMARY NAVIGATION $('nav a').on('click', function (e) { //click on nav e.preventDefault(); //prevent loading var url = this.href; //get UR: to load $('nav a.current').removeClass('current'); $(this).addClass('current'); $('#container').remove(); //remove old $('#content').load(url + ' #container').hide().fadeIn('slow'); // add new }); });

    我不确定这是否是我启动.ajax的方式或者我的jquery没有正确实现的问题。 我觉得是这样的。 有什么想法吗?

    编辑:这是上面脚本的html

       

    UseTime

    Select a Class from the left
    Details

    你正在使用瘦身版的jQu​​ery。 它不支持ajax调用。 使用

      

    而不是它。

    纤细的构造

    有时您不需要ajax,或者您更喜欢使用专注于ajax请求的众多独立库中的一个。 通常,对所有Web动画使用CSS和类操作的组合更为简单。 除了包含ajax和效果模块的常规jQuery版本之外,我们还发布了一个排除这些模块的“瘦身”版本。 总而言之,它排除了ajax,效果和当前已弃用的代码。 jQuery的大小现在很少是一个负载性能问题,但是苗条的构建比常规版本小约6k gzipped字节 – 23.6k vs 30k。 这些文件也可以在npm包和CDN中使用:

     https://code.jquery.com/jquery-3.1.1.slim.js https://code.jquery.com/jquery-3.1.1.slim.min.js 

    从jQuery博客引用

    jQuery 3 slim版本不支持ajax。

    根据发布文档 ,

    除了包含ajax和效果模块的常规jQuery版本之外,我们还发布了一个排除这些模块的“瘦身”版本。 总而言之,它排除了ajax ,效果和当前已弃用的代码。

    要使用.ajax方法,只需使用完整版本。

    试试这个(jquery-3.2.1.min.js)而不是slim(jquery-3.2.1.slim.min.js)