我是 Angular 的新手,在使用一直有效的服务时遇到了麻烦,直到它不起作用。我的服务有以下调用。
this.getForms = function() {
return $http.get("/forms").
then(function(response) {
return response;
}, function(response) {
alert("Error finding forms.");
});
};
Run Code Online (Sandbox Code Playgroud)
当刷新页面(safari)时,触发 getForms,调用 $http.get,我的 Node.js/Express 服务器表单端点正确返回表单数据。
app.get("/forms", function (req, res) {
Form.find({}, function (err, docs) {
if (err) {
server.handleError(res, err.message, "Failed to get forms.");
} else {
res.status(200).json(docs);
}
});
});
Run Code Online (Sandbox Code Playgroud)
但我得到的不是 JSON,而是 304 错误,这表明数据在缓存中可用。但 304 响应标头有一个空数据字符串,因此它不会从缓存返回任何数据。
我的问题是
1)如果数据在缓存中可用,为什么它会调用我的服务器?
2)我如何告诉它不缓存此调用,以便页面可以正确更新表单?