开发者

jQuery, php and FancyBox

开发者 https://www.devze.com 2023-03-18 17:20 出处:网络
I recently installed fancybox to my website, I searched here and at google for this solution but had no good stuff to read.

I recently installed fancybox to my website, I searched here and at google for this solution but had no good stuff to read.

The problem is, I have a php that generates an array and transform it to json_encode, the code is bellow.

$array = ("http://exe开发者_StackOverflow中文版mplo.com/image1.jpg","http://exemplo.com/image2.jpg");
return json_encode($array);

At my javascript, I have this situation called by an ID:

$.ajax({
   type: "GET",
   url: Application.build_url("lista/busca-fotos/"),
   data: "id="+$id,
   success: function(data){
    $.fancybox([data], {
        'padding' : 0,
        'transitionIn' : 'none',
        'transitionOut': 'none',
        'type' : 'image',
        'changeFade': 0
    });                
   }
  });

But, it won't work, I think that I should use parseJSON, but when I do it, the object resultant is null, How can I use this option to show a gallery with images?

It should be like this, this is the online example that works, my data must be replace inside the fancybox([data],...:

    $("#manual2").click(function() {
    $.fancybox([
        'http://farm5.static.flickr.com/4044/4286199901_33844563eb.jpg',
        'http://farm3.static.flickr.com/2687/4220681515_cc4f42d6b9.jpg',
        {
            'href'  : 'http://farm5.static.flickr.com/4005/4213562882_851e92f326.jpg',
            'title' : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
        }
    ], {
        'padding'           : 0,
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'type'              : 'image',
        'changeFade'        : 0
    });
});

Thanks and best regard's, sorry for my bad english.


Your code to create an array does not appear to be syntactically correct. The proper way to initialize an array is like this:

$myArray = array(("item1","item2", "item3", "etc."));

Also, return won't output anything to the client, you should use echo instead.

Your code snippet should look like this:

$array = array(("http://exemplo.com/image1.jpg","http://exemplo.com/image2.jpg");
echo json_encode($array);
0

精彩评论

暂无评论...
验证码 换一张
取 消