title: dojo ajax request not returning json data
body: <p>Not sure where I might have went wrong the code seems fine to me, and I know the file.php -> mod_rewtite -> file.json works as I have tested JSON response from this file via jQuery. In any event the following code bit attached triggers the error response right away instead of going truth the JSON request any guesses why?</p>
  
  <p>sidenotes: I am using latest Dojo Toolkit 1.7.1 from Yandex mirror: <a href="http://yandex.st/dojo/1.7.1/dojo/dojo.js" rel="nofollow">http://yandex.st/dojo/1.7.1/dojo/dojo.js</a></p>
  
  <p>and here is the code for the JSON which does not work</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      require(["dojo/_base/xhr", "dojo/dom", "dojo/_base/array", "dojo/domReady!"],
      function(xhr, dom, arrayUtil) {
  
          // Keep hold of the container node
          var containerNode = dom.byId("content");
  
          // Using xhr.get, as we simply want to retrieve information
          xhr.get({
              // The URL of the request
              url: "file.json?path=&lt;?php echo $_GET['path']; ?&gt;&amp;callback=?",
              // Handle the result as JSON data
              handleAs: "json",
              // The success handler
              load: function(jsonData) {
                  // Create a local var to append content to
                  var html = "";
                  // For every news item we received...
                  arrayUtil.forEach(jsonData, function(item) {
                      // Build data from the JSON 
                      html += "&lt;div class='product' data='" + item.path + "'&gt;";
                      html += "&lt;div class='like'&gt;&lt;/div&gt;";
                      html += "&lt;img src='thumb.php?q=100&amp;w=298&amp;h=238&amp;a=t&amp;src='" + item.thumb + "' width='298' height='238'/&gt;";
                      html += "&lt;div class='title'&gt;" + item.name + "&lt;/div&gt;";
                      html += "&lt;div class='description'&gt;&lt;/div&gt;&amp;nbsp;&lt;strong&gt;Filesize:&lt;/strong&gt;" + item.size + "&lt;div style='clear:both;height:8px;'&gt;&lt;/div&gt;&amp;nbsp;about" + item.date + " ago&lt;div style='clear:both;height:8px;'&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class='clear'&gt;&lt;/div&gt;&lt;/div&gt;";
                  });
                  // Set the content of the news node
                  containerNode.innerHTML = html;
              },
              // The error handler
              error: function() {
                  containerNode.innerHTML = "News is not available at this time."
              }
          }); 
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Also here is the file.php -> file.json code bit in even you need it, but as I said I do not suspect it as it works perfectly with jQuery</p>
  
  <pre><code>&lt;?php
  
  $dir = $_GET['path'] . "/";
  
  function time_since($since) {
      $chunks = array(
          array(60 * 60 * 24 * 365 , 'year'),
          array(60 * 60 * 24 * 30 , 'month'),
          array(60 * 60 * 24 * 7, 'week'),
          array(60 * 60 * 24 , 'day'),
          array(60 * 60 , 'hour'),
          array(60 , 'minute'),
          array(1 , 'second')
      );
  
      for ($i = 0, $j = count($chunks); $i &lt; $j; $i++) {
          $seconds = $chunks[$i][0];
          $name = $chunks[$i][1];
          if (($count = floor($since / $seconds)) != 0) {
              break;
          }
      }
  
      $print = ($count == 1) ? '1 '.$name : "$count {$name}s";
      return $print;
  }
  
  $dh = opendir($dir);
  $files = array();
  while (($file = readdir($dh)) !== false) {
      if ($file != '.' AND $file != '..' ) {
          if (filetype($dir . $file) == 'file') {
              $files[] = array(
                  'id' =&gt; md5($file),
                  'name' =&gt; htmlentities(md5($file)),
                  'size' =&gt; filesize($dir . $file). ' bytes',
                  'date' =&gt; time_since(date("ymd Hi", filemtime($dir . $file))),
                  'path' =&gt; $dir . $file,
                  'thumb' =&gt; $dir . 'small/' . $file
              );
          }            
      }
  }
  closedir($dh);
  
      $json = json_encode($files);
  
      $callback = $_GET['callback'];
      echo $callback.'('. $json . ')';
  
  ?&gt;
  </code></pre>