title: Successfully passing json_encode'd variables from PHP to external .js file?
body: <p>First off let me say, I've never used JSON or AJAX before, but I think I understand the concept at least.</p>
  
  <p>I'm only trying to pass some PHP values to a jquery function (located in an external .js file). I've tried everything I can possibly think of, and don't know what's going wrong here.</p>
  
  <p>In index.php I have:</p>
  
  <pre><code>&lt;?php
  $data = array(1 =&gt; 'thisor', 2 =&gt; 'thatttt');
  echo json_encode($data);
  ?&gt;
  </code></pre>
  
  <p>..which obviously isn't the real data I'm wanting to pass, but it's just for testing. 
  In my .js file I have the function:</p>
  
  <pre><code>  $.getJSON("index.php", function(data){
       alert('data loaded' + data);
    })
    .error(function() { alert("error"); });
  </code></pre>
  
  <p>and every time, it's throwing the error. However I've noticed if I use $.post with the same exact code following it, it doesn't throw an error anymore, and returns the data.</p>
  
  <p>Also, is it necessary to 'echo' the json_encode? What if I don't want this information displayed on my webpage? Or.. I'm misunderstanding something here possibly.</p>
  
  <p>Also x2, if it's worth noting, I read about 'header('Content-type: application/json');' that may need to go into the PHP file.. however when I did that, it no longer rendered the webpage in the browser, and instead just output the contents in plain text. Am I needing to do this somewhere else / make another external PHP file?</p>
  
  <p>Apologies for any ridiculous questions, it really is my first day trying to learn this thing.</p>