我对 AngularJS 很陌生。我想将注册数据发布到 json 文件。 Post 请求工作正常,但数据未写入文件。我无法理解这个立场。我的帖子请求代码有问题吗?我该如何解决这个问题?谢谢!
var regModel = {
FirstName: 'Someone',
LastName: 'Somebody',
Address: 'somewhere',
Email: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="196a76747c6d7170777e597e74787075377a7674" rel="noreferrer noopener nofollow">[email protected]</a>'
};
$scope.insertUser = function () {
$http.post('../DB/users.json', regModel).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}
最佳答案
根据您当前的设置,您的发布请求将在请求内容中包含您的 regModel 对象。在服务器端,您可以获取正文或内容,然后将其写入文件。
关于javascript - AngularJS 使用 $http.post() 将模型发布到 json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27417705/