title: Slim PHP returning JSON
body: <p>So basically I have my backbone application making an ajax GET call to my slim php app. It expects JSON dataType in return.</p>
  
  <pre><code>$.ajax({
          url: './myroute',
          type: 'GET',
          dataType: "json",
          data: { username: username, password: password },
          success: function(data) {},
          error: function(data) {}
  });
  </code></pre>
  
  <p>In my slim file I have:</p>
  
  <pre><code>$app-&gt;get('/myroute', function() use ($app) {
  
      // all the good stuff here (getting the data from the db and all that)
  
      $dataArray = array('id' =&gt; $id, 'somethingElse' =&gt; $somethingElse);
  
      $response = $app-&gt;response();
      $response['Content-Type'] = 'application/json';
      $response-&gt;body(json_encode($dataArray));
  
  });
  
      // Tried with these in the above GET request as well:
      // $app-&gt;contentType('application/json');
      // echo json_encode($dataArray);
  </code></pre>
  
  <p>While my request properly goes through (200), and I properly get my JSON data, the error is because it also returns the full index.php page data as well (which my javascript dataType: "json" does not allow, which triggers the error)</p>
  
  <p>I figured setting the content type to "application/json" would solve this, but it still returns the full page contents as well as the json data.</p>
  
  <p><strong>Edit for reference</strong></p>
  
  <p>I used to have it set up so that Slim would render my html like:</p>
  
  <pre><code>$app-&gt;get('/', function () use ($app) {
      // would just have my main page files in home.php instead of index.php
      $app-render('home.php');
  });
  </code></pre>
  
  <p>So that way there, there was no html page data being returned from index.php. But the way pushState is, I have to have my javascript scripts running on index.php, otherwise my pages wont be loaded properly since when they're requested, the scripts aren't there to delegate where the route should go.</p>
  
  <p>Any help is appreciated!</p>
  
  <p>Thanks SO!</p>