Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $http post调用挂起_Javascript_Angularjs_Redirect_Post - Fatal编程技术网

Javascript $http post调用挂起

Javascript $http post调用挂起,javascript,angularjs,redirect,post,Javascript,Angularjs,Redirect,Post,我正在尝试创建一个页面来显示所有论坛帖子…一切正常,但我注意到在firebug中创建帖子(当它重定向以显示所有帖子时)后,帖子调用会挂起很长时间。然而,数据是通过发送的,尽管看起来post调用仍处于挂起状态……因为它显示在页面上,包含所有的post,这些post会立即加载。我现在就是这样做的 post控制器(post.js): 如您所见,现在,我正在post调用行之后执行重定向($location.path)。重定向的工作原理如下所示…但是-如果我尝试将重定向放入success函数: $http

我正在尝试创建一个页面来显示所有论坛帖子…一切正常,但我注意到在firebug中创建帖子(当它重定向以显示所有帖子时)后,帖子调用会挂起很长时间。然而,数据是通过发送的,尽管看起来post调用仍处于挂起状态……因为它显示在页面上,包含所有的post,这些post会立即加载。我现在就是这样做的

post控制器(post.js):

如您所见,现在,我正在post调用行之后执行重定向(
$location.path
)。重定向的工作原理如下所示…但是-如果我尝试将重定向放入
success
函数:

$http.post('/api/post', $scope.post).success(function() {$location.path('/forum'); console.log("no errors whoohoo")});
重定向从未发生,它只是挂起post调用。有人知道发生了什么事吗?我认为post调用应该只需要几毫秒就可以完成(它只是存储了一个帖子标题和内容)

无论我用哪种方式,post调用都会挂起…只是第二种方式不会重定向页面

更新

正如评论中所建议的,我的服务器端代码有问题-我可能已经隔离了这个问题

这是当我想列出页面上的所有帖子(api.js)时调用的函数:

console.log
消息从未出现,因此它一定是挂断的地方…有什么想法吗

调用此函数的代码区域如下所示:

app.route('/api/post')
    .get(api.posts);

这是我的一条快车路线。

事实证明,使用
$location.path('/xxx')
是不够的,我还需要在快车端使用
res.redirect
,重定向才能真正起作用。(必须同时使用两者)。

您是否尝试过使用.then而不是.success?在上面的示例中,它是否记录了“no errors whoohoo”@JaredReeves刚刚尝试了它-仍然挂起。@JaredReeves-消息也不会被记录…如果它没有进入成功回调,则表示$http可能失败。你确定api正在返回任何东西吗?你是否也尝试过放置http错误处理程序?
exports.posts = function(req, res) {
  return Post.find(function (err, posts) {
    if (!err) {
      console.log(posts + " server side posts function route");
      return res.json(posts);
    } else {
      return res.send(err);
    }
  });
};
app.route('/api/post')
    .get(api.posts);