dongyue5686 2011-07-05 17:48
浏览 47
已采纳

jQuery,php和FancyBox

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://exemplo.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.

  • 写回答

1条回答 默认 最新

  • douyi3676 2011-07-05 18:27
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥66 定制开发肯德基自动化网站下单软件
  • ¥20 vscode虚拟环境依赖包未安装
  • ¥15 odoo17关于owl开发js代码问题
  • ¥15 光纤中多普勒频移公式的推导
  • ¥15 怎么制作一个人脸识别门禁系统
  • ¥20 大华dss监控平台网络关闭登不进去
  • ¥15 请使用蚁群算法解决下列问题,并给出我完整的代码
  • ¥20 关于php录入完成后,批量更新数据库
  • ¥15 请教往复密封润滑问题
  • ¥15 cocos creator发布ios包