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

报告相同问题?

悬赏问题

  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵
  • ¥15 cfx离心泵非稳态计算