title: REST API, return JSON objects from PHP to JS file
body: <p>I am writing some kind a rest API for the first time, so I need a little help. I found few solutions for my problems here on stackoverflow and I managed to solve them. But now I came to another one and could not find a solution.</p>
  
  <p>First of all, js file code.</p>
  
  <pre><code>$.getJSON('test.php', function(data) {
      console.log(data);
      articles = data;
      return articles;            
  });
  </code></pre>
  
  <p>This is js file, from which I send request to php file and then get data back. The thing is, data I get back from php looks fine in browser console when I log it, all data is there. But when I try to use that data on page (with my return statement), it does not work. If I replace return articles row with </p>
  
  <pre><code>return [{"name":'Name goes here',"description":'Description goes here'}];
  </code></pre>
  
  <p>it works fine on a page. This is bothering me, because in browser console I can see all the objects that have been returned from php file, but they do not work on page. I hope any of you can help me. I am pasting my php file below.</p>
  
  <pre><code>$json = array(
          array(
              "name" =&gt; 'Name goes here',
              "description" =&gt; 'Test description.',
              "link" =&gt; 'articles/articleName',
              "img" =&gt; '../images/article1.jpg'
          ),
          array(
              "name" =&gt; 'Name goes here 2',
              "description" =&gt; 'Not ready yet',
              "link" =&gt; '#',
              "img" =&gt; ''
          ),
          array(
              "name" =&gt; 'Name goes here 3',
              "description" =&gt; 'Not ready yet',
              "link" =&gt; '#',
              "img" =&gt; ''
          )
      );
  
      $jsonstring = json_encode($json, JSON_PRETTY_PRINT);
      echo $jsonstring;
  </code></pre>