title: Getting JSON data from Grails backend using Angularjs
body: <p>I have the following problem. I have controller in Grails, which returns list in Json format:</p>
  
  <pre><code>render([tweets: tweets.take(2).collect { tweet -&gt; [id: tweet.id, content: tweet.tweetContent]}] as JSON)
  </code></pre>
  
  <p>This is my UrlMapping:</p>
  
  <pre><code>"/tweets/"(controller: "tweets", parseRequest: true) {
          action = [GET: "list"]
  </code></pre>
  
  <p>So when I just open this url in any browser, I am getting list of elements in JSON format:</p>
  
  <pre><code>{"tweets":[{"id":375238019298914304,"content":"@RonNegrita @Paolah_96 jajajajajajajajaja pues ale Negrita q nos lo has xk este del Tuit prima JAJAJAHAHAHAHA"},{"id":375238020360048640,"content":"My 38 Life Goals for next 10 years. Brewery's, Alabama Football, Concerts, Companies, Kids, Fiji, &amp; more: http://t.co/behxfnCo5t"}]}
  </code></pre>
  
  <p>Then I am trying to get this elements in HTML page using Angularjs. This is my simple code for html page:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en" ng-app id="ng-app"&gt;
  &lt;head&gt;
  &lt;title&gt;Page Title&lt;/title&gt;
  &lt;script src="js/angular.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  function PostsCtrlAjax($scope, $http)
  {
  $scope.tweets = []
  $http.get('http://localhost:8080/trutto-api/tweets/').success(function(data)
  {
  $scope.tweets = data; // response data 
  });
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="ng-app" ng-app ng-controller="PostsCtrlAjax"&gt; 
  &lt;li ng-repeat="tweet in tweets&gt;{{tweet.id}} - {{tweet.content}}&lt;/li&gt;
  &lt;/h2&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I am trying to get data in Chrome browser, I am getting to following error:</p>
  
  <pre><code>"Xml http request cannot load http://localhost:8080/trutto-api/tweets/. Original null is not allowed by access-control-allow-origin"
  </code></pre>
  
  <p>I found question regarding this error here, it suggests starting Chrome with this command:</p>
  
  <pre><code>"- allow-file-access-from-files". 
  </code></pre>
  
  <p>I tried it - it doens't work, returns the same error.
  Then I tried it on Glassfish server -> opening in Chrome leads to same error.</p>
  
  <p>Opening in Mozilla Firefox leads to the following error:</p>
  
  <pre><code>SyntaxError: JSON.parse: unexpected end of data.
  </code></pre>
  
  <p>How should I fix it? Thank you in advance.</p>