Here is my problem.
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.
So, when I click on one of these links handled this 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);
}
});
});
This solution works fine. But when I use
var img = [dataX];
instead of
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'},];
I'm get Pop-up window with responce text.
Demo
What i'm doing wrong?
- fancyBox - jQuery Plugin
- version: 2.0.5 (21/02/2012)
- jQuery 1.7 - latest
code of 'getfile.php'
function directoryToArray($directory, $recursive = true) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $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'},
";
}
UPDATE
$(".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);
}
});
});
See Question&Answers more detail:
os