javascript - AngularJS 使用 $http.post() 将模型发布到 json 文件

标签 javascript json angularjs http

我对 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/

相关文章:

javascript - 成功返回数据的 Angularjs 路由解析产生未定义的值

javascript - 根据 Angular JS 中的属性值在列表中查找对象

javascript - 传递的 Angular UI 模态数据为 null

javascript - XMLHttpRequest 打开函数的异步事件监听器

javascript - javascript中唯一键上的俱乐部JSON对象

javascript - 在 d3.js map 中添加工具提示

php - 在 LAMP 服务器上使用 PHP 从 MySQLi 输出 JSON api

javascript - 带有回调的 JSON Schema 解析器/验证器?

javascript - 从字符串中删除某个字符的所有实例

javascript - 用背景颜色智能地填充 Bootstrap 列