title: Reading and writing to a server-side file in AngularJS
body: <p><b>I'm attempting to create a simple guestbook</b> with AngularJS, and read and write the names to a simple file.  Trouble is, I can't seem to get my code to even read from the file.</p>
  
  <p>This is my directory structure:</p>
  
  <p><img src="https://i.stack.imgur.com/iNzmA.png" alt="Directory Structure"></p>
  
  <p>This is index.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html ng-app&gt;
      &lt;head&gt;
          &lt;meta charset="ISO-8859-1"&gt;
          &lt;title&gt;GuestBook&lt;/title&gt;
          &lt;script src="http://code.angularjs.org/angular-1.0.0rc3.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="javascript/user.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Welcome!&lt;/h1&gt;
          &lt;div ng-controller="UserCtrl"&gt;
              &lt;ul class="unstyled"&gt;
                  &lt;li ng-repeat="user in users"&gt;
                      {{user}}
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is user.js (Based off <a href="https://stackoverflow.com/questions/9127447/loading-an-array-from-txt-file"><b>this question/answer</b></a>):</p>
  
  <pre><code>function UserCtrl($scope) {
  
      $scope.users = $(function() {
          $.get('data/users', function(data) {
              var array = data.split(',');
              console.log(array);
          });
      });
  }
  </code></pre>
  
  <p>And this is my users file:</p>
  
  <pre><code>John,Jacob,James
  </code></pre>
  
  <p>I'm expecting this outcome:</p>
  
  <h1>Welcome!</h1>
  
  <ul>
  <li>John</li>
  <li>Jacob</li>
  <li>James</li>
  </ul>
  
  <p>But instead, all I get is:</p>
  
  <h1>Welcome!</h1>
  
  <p>So my question is, how can I populate $scope.users with the names in the users file?</p>
  
  <p>I know I've got my AngularJS set up correctly because I was able to get the desired result when I hard-coded it:</p>
  
  <pre><code>$scope.users =[John,Jacob,James];
  </code></pre>
  
  <p>I've also spent a lot of time googling and searching Stack Overflow for how to read and write to a file with JavaScript and/or AngularJS, but:</p>
  
  <ol><li>No one seems to be trying to do exactly what I'm trying to do;</li><li>The instructions are either confusing or not really applicable to what I'm trying to do.</li></ol>
  
  <p>I'm also not sure where to begin to write code that will persist names to the users file -- but I'll be happy if I can just read the file for now, and ask how to write to it later in a separate question.  (But extra gratitude if you do also show me how to write to it.)</p>