title: AJAX fails while get data from while() loop in php
body: <p>When I use <code>json_encode($array)</code> I get the data properly but when I use json_encode within an array which is looped I Get the following error</p>
  
  <blockquote>
    <p>[object Object] parsererror SyntaxError: Unexpected token {</p>
  </blockquote>
  
  <hr>
  
  <p>I'm using ajax to get json data from functions.php</p>
  
  <pre><code>$(function() {
  $('#get').click(function(){
          $.ajax({
          url: 'http://android.ezinfotec.com/functions.php',
          type : 'GET',
          data : 'method=getquestions',           
          dataType : 'json',
          success : function(s) {
              console.log(s);
          },
          error: function(XMLHttpRequest,textStatus,errorThrown)
          {
              console.log(XMLHttpRequest+' '+textStatus+' '+errorThrown);
          }
      });
  });
  });
  </code></pre>
  
  <p>The functions.php</p>
  
  <pre><code>&lt;?php
  header('Content-type: application/json');
  include("connect.php");
  if($_GET['method'] == 'getquestions')
  {
  $query = mysql_query("select * from questions");
  while($fetch = mysql_fetch_array($query))
  {
  
  $output = array(
                  "id" =&gt; $fetch['id'],
                  "answers" =&gt; $fetch['answers'],
                  "status" =&gt; $fetch['ans_status'],
                  "postedon" =&gt; substr($fetch['month'],0,3).' '.$fetch['day'].' '.$fetch['year'],
                  "question" =&gt; $fetch['question'],
                  "category" =&gt; $fetch['category'],
                  "parent" =&gt; $fetch['parentcategory'],
                  "authorid" =&gt; $fetch['author'],
                  "authorname" =&gt; $fetch['author_name']                   
                  );
                  echo json_encode($output);
  }
  
  }
  </code></pre>
  
  <p>In the above php code if I remove the while loop and simple define custom values to the variable i get perfect data in the html page.</p>
  
  <p><strong>Note</strong>: There is no cross domain issue as I have many functions working except for <code>getquestions();</code></p>
  
  <p>You can check the json output at <a href="http://android.ezinfotec.com/functions.php?method=getquestions" rel="nofollow">http://android.ezinfotec.com/functions.php?method=getquestions</a></p>