未捕获的TypeError:$ .ajax(...)。success不是函数 [英] Uncaught TypeError: $.ajax(...).success is not a function

查看:129
本文介绍了未捕获的TypeError:$ .ajax(...)。success不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jQuery的新手,并在 node.js 上使用了一个使用此代码段的旧教程:

I'm new to jQuery and using a little old tutorial on node.js that uses this snippet :

$(function () {    
    var roomId;

    $.ajax({
        type: "GET",
        url: "/api/rooms"
    }).success(function (rooms) { 
        roomId = rooms[0].id;
        getMessages();
        $.each(rooms, function (key, room) {
            var a = '<a href="#" data-room-id="' + room.id + '" class="room list-group-item">' + room.name + '</a>';
            $("#rooms").append(a);
        });

    });

    [...]       

});

但是我收到此错误


未捕获TypeError:$ .ajax(...)。成功不是函数

Uncaught TypeError: $.ajax(...).success is not a function

at })。成功(函数(房间){

我想知道这里有什么问题?

I'm wondering what can be wrong here?

推荐答案

对ajax的调用应如下所示:

The call to ajax should look like:

$.ajax({
    type: "GET",
    url: "/api/rooms",
    success: function (rooms) { 

    }
});

你没有方法链接成功函数,它是其中之一字典参数中的条目。

You don't method chain the success function, it is one of the entries in the dictionary argument.

这篇关于未捕获的TypeError:$ .ajax(...)。success不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆