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

时间:2015-04-10 13:46:56

标签: angularjs express mean meanjs

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

当我检查服务器端的id时,它正确返回。但在客户方面,我并没有以同样的方式得到它。例如:如果Id是5527d2ed7ab73f7e412117c9,那么我将得到的是角度:

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

1 个答案:

答案 0 :(得分:0)

尝试返回一个对象,因为result._idstring,资源期待object

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

console.log(response.id)