从服务器向客户端发送数据无法正常工作

Sending data from server to client not working properly

我想在我的 meanjs 应用程序中将最后一个插入 ID 从 express 发送到 angularjs

当我在服务器端检查 id 时,它正确返回。但在客户端,我并没有以同样的方式得到它。例如:如果 ID 是 5527d2ed7ab73f7e412117c9,在 angular 中,我得到的是:

Resource {0: "5", 1: "5", 2: "2", 3: "7", 4: "d", 5: "2", 6: "e", 7: "d", 8: "7", 9: "a", 10: "b", 11: "7", 12: "3", 13: "f", 14: "7", 15: "e", 16: "4", 17: "1", 18: "2", 19: "1", 20: "1", 21: "7", 22: "c", 23: "9", $promise: undefined, $resolved: true, $get: function, $save: function, $query: function…}0: "5"1: "5"2: "2"3: "7"4: "d"5: "2"6: "e"7: "d"8: "7"9: "a"10: "b"11: "7"12: "3"13: "f"14: "7"15: "e"16: "4"17: "1"18: "2"19: "1"20: "1"21: "7"22: "c"23: "9"$promise: undefined$resolved: true

我的密码是

服务器代码

exports.save(function (err, result) {
    if (err) {
        return res.send(400, err);
    }
    console.log(result._id);
    res.jsonp(result._id);
});

客户代码

  $scope.$save(function (response) {
    console.log(response)
  }, onError);

尝试返回一个对象,因为 result._id 是一个 string 并且资源需要一个 object.

res.jsonp({id : result._id});

console.log(response.id)