title: FancyBox get href for images via AJAX
body: <p>Here is my problem.</p>
  
  <p>I use FancyBox for showing images, which getting via AJAX.
  There isn't exist images on page when page is loaded, only links with attributes with names of galleries.</p>
  
  <p>So, when I click on one of these links handled this code:</p>
  
  <pre><code>    $(".fancybox-manual-c").live('click',function() {
              $.ajax({
                      type : 'POST',
                      data : {'gal' : $(this).attr('rel')},
                      url : 'http://polygon.goracio.com.ua/gallery/getfiles.php',
                      //dataType: 'json',
                      complete: function(data) {
                              var dataX = data.responseText;
                              console.log(data.responseText);
                              var img = [
                                      {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-30711.jpg'},
                                      {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-27082.jpg'},
                                      {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-30988.jpg'},
                                      {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-30858.jpg'},
                                      {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-23424.jpg'},];
                              var opts = {
                                      prevEffect : 'none',
                                      nextEffect : 'none',
                                      helpers : {
                                              thumbs : {
                                                      width: 75,
                                                      height: 50
                                              }
                                      }
                              };
                              $.fancybox(img, opts);
                          }
              });
      });
  </code></pre>
  
  <p>This solution works fine. But when I use </p>
  
  <pre><code>    var img = [dataX];
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>            var img = [
                  {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-30711.jpg'},
                  {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-27082.jpg'},
                  {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-30988.jpg'},
                  {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-30858.jpg'},
                  {href:'/gallery/galleries/gallery1/wallpapers_by_ellin-23424.jpg'},];
  </code></pre>
  
  <p>I'm get Pop-up window with responce text.</p>
  
  <p><a href="http://polygon.goracio.com.ua/gallery/" rel="nofollow">Demo</a></p>
  
  <p>What i'm doing wrong?</p>
  
  <ul>
  <li>fancyBox - jQuery Plugin</li>
  <li>version: 2.0.5 (21/02/2012)</li>
  <li>jQuery 1.7 - latest</li>
  </ul>
  
  <p>code of 'getfile.php'</p>
  
  <pre><code>function directoryToArray($directory, $recursive = true) {
      $array_items = array();
      if ($handle = opendir($directory)) {
          while (false !== ($file = readdir($handle))) {
              if ($file != "." &amp;&amp; $file != "..") {
                  if (is_dir($directory. "/" . $file)) {
                      if($recursive) {
                          $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));
                      }
                      $directory = str_replace('./galleries/', '', $directory);
                      $file = $directory . "/" . $file;
                      $array_items[]= preg_replace("/\/\//si", "/", $file);
                  } else {
                      $directory = str_replace('./galleries/', '', $directory);
                      $file = $directory . "/" . $file;
                      $array_items[] = preg_replace("/\/\//si", "/", $file);
                  }
              }
          }
          closedir($handle);
      }
      return $array_items;
  }
  header("Content-type: text/plain;charset=utf-8");
  $arrays = directoryToArray( "./galleries/".$_POST['gal']);
  foreach($arrays as $array){
      echo "{href:'/gallery/galleries/$array'}, \n";
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>        $(".fancybox-manual-ajax").live('click',function() {
              $.ajax({
                  type : 'POST',
                  data : {'gal' : $(this).attr('rel')},
                  url : 'http://polygon.goracio.com.ua/gallery/getfiles.php',
                  dataType: 'text',
                  complete: function(data) {
                      var dataX = data.responseText;
                      var dataXsplit = dataX.split(',');
                      var dataXarrayObj = new Array(), i;
                      for(i in dataXsplit){
                          if(dataXsplit[i].length){ //remove last empty element after .split()
                              dataXarrayObj[i] = $.parseJSON(dataXsplit[i]);
                          }
                      }
                      var opts = {
                          prevEffect : 'none',
                          nextEffect : 'none',
                          helpers : {
                              thumbs : {
                                  width: 75,
                                  height: 50
                              }
                          }
                      };
                      $.fancybox(dataXarrayObj, opts);
                  }
              });
          });
  </code></pre>