title: Javascript JSON.parse responseText "Unexpected end of input"
body: <p>I keep getting "Uncaught SyntaxError: Unexpected end of input " in the browser console when running this JSON.parse. I tried shortening the $element to just $entry but still no success: </p>
  
  <pre><code>function getFileList() {
          var elements;   
      var foo = document.getElementById("filelist");
      var xhr = new XMLHttpRequest();
      xhr.addEventListener("load", complete, true);
  
           // foo.innerHTML= xhr.responseText;
      xhr.onreadystatechange = function () {
          console.log(JSON.parse(xhr.responseText));
  
      }
  
  
      xhr.open("GET", "php/dir_list.php", true);
      xhr.send(null);
  
      function complete() {
          eventAssign();
          xhr.removeEventListener("load", complete, false);
      }
  
  }
  
  
  
  &lt;?php
  $files = array();
  if ($handle = opendir('/trunk')) {
      $i = 0;
      while (false !== ($entry = readdir($handle))) {
          if ($entry != "." &amp;&amp; $entry != "..") {
              $element = '&lt;li&gt;&lt;a class="files" id="listFile'.$i.'" data-filename="'.$entry.'" href=php/download.php?filename='.$entry.'&gt;'.$entry.'&lt;/a&gt;&lt;/li&gt;';
              $checksum = shell_exec("sum /trunk/".$entry);
              $files[$entry] = array( $element, $checksum );
              $i++;
          }
      }
      closedir($handle);
  }
  $files =  json_encode($files);
  echo $files;
  ?&gt;
  </code></pre>
  
  <p>EDIT: Fixed getFileList() pasting. </p>
  
  <p>Just to avoid confusion, issue still persists. Here is the json output from php dir_list.php:</p>
  
  <p>webserver httpfiles # php php/dir_list.php</p>
  
  <pre><code>{"lynx2.8.5rel.1-DOSc.zip":["&lt;li&gt;&lt;a class=\"files\" id=\"listFile0\" data-filename=\"lynx2.8.5rel.1-DOSc.zip\" href=php\/download.php?filename=lynx2.8.5rel.1-DOSc.zip&gt;lynx2.8.5rel.1-DOSc.zip&lt;\/a&gt;&lt;\/li&gt;","02625  2406\n"],"try.zip":["&lt;li&gt;&lt;a class=\"files\" id=\"listFile1\" data-filename=\"try.zip\" href=php\/download.php?filename=try.zip&gt;try.zip&lt;\/a&gt;&lt;\/li&gt;","18695    74\n"],"darn.tar.gz":["&lt;li&gt;&lt;a class=\"files\" id=\"listFile2\" data-filename=\"darn.tar.gz\" href=php\/download.php?filename=darin.tar.gz&gt;darin.tar.gz&lt;\/a&gt;&lt;\/li&gt;","56880   292\n"],"songs.txt":["&lt;li&gt;&lt;a class=\"files\" id=\"listFile3\" data-filename=\"songs.txt\" href=php\/download.php?filename=songs.txt&gt;songs.txt&lt;\/a&gt;&lt;\/li&gt;","43469     1\n"],"CentOS-6.3-x86_64-minimal-EFI.iso":["&lt;li&gt;&lt;a class=\"files\" id=\"listFile4\" data-filename=\"CentOS-6.3-x86_64-minimal-EFI.iso\" href=php\/download.php?filename=CentOS-6.3-x86_64-minimal-EFI.iso&gt;CentOS-6.3-x86_64-minimal-EFI.iso&lt;\/a&gt;&lt;\/li&gt;","04152 372736\n"]}
  </code></pre>