微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – jQuery 3 slim ajax基本示例

我是jQuery 3的新手.以下是一个基本的fiddle,使用以前版本的jQuery,但不适用于jQuery 3

$(function() {
    $.ajax({
        url: '/echo/json',
        type: 'GET',
        dataType: 'json',
        success: function(data) {
            console.log(data)
        }
    });
})

在控制台中,我收到此错误

jquery-3.1.1.slim.min.js:2 jQuery.Deferred exception: $.ajax is not a function TypeError: $.ajax is not a function

jquery-3.1.1.slim.min.js:2 Uncaught TypeError: $.ajax is not a function(…)

为什么?

解决方法:

jQuery 3 slim版本不支持ajax.

根据release docs,

Along with the regular version of jQuery that includes the ajax and
effects modules, we’re releasing a “slim” version that excludes these
modules. All in all, it excludes ajax, effects, and currently
deprecated code.

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

这是工作fiddle

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐