title: How can I use Angular $http.post() to update a JSON file?
body: <p>For now, all I'm trying to do is read in a simple JSON file, allow the user to edit the contents, and then save it back to the same file. I've read several answers like <a href="https://stackoverflow.com/questions/11442632/how-can-i-post-data-as-form-data-instead-of-a-request-payload/14868725">this</a>, but I'm not dealing with form data or trying to cut out jquery and my understanding (probably the issue) is that it shouldn't be that complicated.</p>
  
  <p>Working off of <a href="https://stackoverflow.com/a/19969705/5071387">this</a> answer, here's what I've got:</p>
  
  <pre><code>&lt;div ng-controller="myCtrl as items"&gt;
      &lt;table&gt;
          &lt;tr ng-repeat="item in items.testData"&gt;
              &lt;td&gt;&lt;strong&gt;Name:&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input ng-model="item"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;button ng-click="items.update()"&gt;Submit&lt;/button&gt;
      &lt;p&gt;{{items.msg}}&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>In the app.js:</p>
  
  <pre><code>(function() {
  var app = angular.module("myApp", []);
  
  app.controller("myCtrl", ["$http", function($http) {
      var list = this;
      this.testData = [];
      $http.get("test.json").success(function(data) {
          list.testData = data);
      });
      this.msg = "";
  
      this.update = function() {
          $http.post("test.json", list.testData);
          this.msg = "saved:" + JSON.stringify(list.testData);
      };
  }]);
  })();
  </code></pre>
  
  <p>And finally the JSON, just so you see what I see:</p>
  
  <pre><code>[
  "first item",
  "second item",
  "3rd item",
  "And fourth"
  ]
  </code></pre>
  
  <p>I'm only working locally right now, so there shouldn't be any issue with my server failing to understand the output (as discussed <a href="https://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-data?lq=1">here</a>). I'm just going JSON to JSON.</p>
  
  <p>Now, my observations-</p>
  
  <ol>
  <li>(most importantly) <em>test.json</em> never changes when I update(), maybe because</li>
  <li>testData doesn't seem to actually change, according to the output in msg. Is something wrong with my ng-model? It works in the <a href="http://jsbin.com/EvOSAqo/1/edit?html,css,js,output" rel="nofollow noreferrer">above example</a>.</li>
  <li>There's no error for trying to post to <em>test.json</em>, but if I instead set the destination as <em>test-new.json</em>, I get <strong>Access to restricted URI denied</strong>. Can I not actually write to a local file at all?</li>
  </ol>
  
  <p>Hopefully, I'm right that this deserved its own question; nothing else I looked at seemed to answer just the basic problems I'm having. Any help greatly appreciated.</p>