title: echo json_encode just shows data in browser and jquery cant get it (PHP MVC)
body: <p>i built my own PHP MVC website . i want the admin can see the data's without refresh using jQuery and getJSON function</p>
  
  <p><strong>index method in admins controller</strong> </p>
  
  <pre><code>public function index(){
      session_start();
      if($this-&gt;isLogin()){
          echo json_encode($this-&gt;adminModel-&gt;getAdsWithNoPermission());
  
      }else{
          die("404 NOT FOUND");
      }
  
  }
  </code></pre>
  
  <p><strong>Home method in admins controller</strong></p>
  
  <pre><code>public function home(){
      session_start();
      if($this-&gt;isLogin()){
          $this-&gt;view('admin/index');
      }else{
          redirect('pages/notfound');
      }
  }
  </code></pre>
  
  <p><strong>Jquery script in admin/index view</strong></p>
  
  <pre><code>function adsOutput(){
      $.getJSON('&lt;?php echo URL_ROOT;?&gt;admins/index',function(data){
          var adminid = '&lt;?php echo $_SESSION['admin_id'];?&gt;';
          $.each(data,function(i,item){
              $('#adsOutput').append('&lt;tr&gt;');
              $('#adsOutput').append('&lt;th score="row"&gt;' + i);
              $('#adsOutput').append('&lt;td&gt;' + data[i].title + '&lt;/td&gt;');
              $('#adsOutput').append('&lt;td&gt;' + data[i].subject + '&lt;/td&gt;');
              $('#adsOutput').append('&lt;td&gt;' + data[i].description + '&lt;/td&gt;');
              $("#adsOutput").append('&lt;td&gt;&lt;input type="submit" class="publish btn btn-success" value="publish" adid=' + data[i].id +  ' adminid=' +adminid +' &gt;&lt;input type="submit" class="delete btn btn-danger" value="delete" adid=' + data[i].id +  ' adminid=' +adminid +' &gt;&lt;/td&gt;' );
  
              console.log(data);
  
          })
      })
  }
  </code></pre>
  
  <p>as you can see i wrote 2 methods home and index . the index just echo the data comes from model in json way . and the home return the homepage views . in the jquery function i'm getting json file from index page and shows data in the html. 
  <strong>codes works correctly</strong> but i want to know how can i have just one index method like this </p>
  
  <pre><code>public function index(){
  session_start();
  if($this-&gt;isLogin()){
      echo json_encode($this-&gt;adminModel-&gt;getAdsWithNoPermission());
      $this-&gt;view('admins/index');
  }else{
      die("404 NOT FOUND");
  }
  
  }
  </code></pre>
  
  <p>because when i wrote the index like this and remove the home method the output is this :  <a href="https://pasteboard.co/Hw62NKh.jpg" rel="nofollow noreferrer">https://pasteboard.co/Hw62NKh.jpg</a></p>
  
  <p>and if there is no way that i can handle all things in index method, and home method needs to be exist , how can i hide index methods (avoid admin to get there by URL) just to use it for jquery .</p>