duanhao4909 2010-11-17 21:47
浏览 54
已采纳

从rss获取另一个域的图像(然后附加)

I want to get images from a flickr rss but this code won't get them. This is what I got up with after some help from my original qustion here : Jquery in Internet Explorer: find image problem(works in FF and Chrome)

The problem is getting the data in right format to my web page. My page's URL is : zalastax.co.cc/pictures.html

Javascript:

$.ajax({
    type: "GET",
    url: "js/getflickreasy.php",
    dataType: "xml",
    success: function(data) {
        $(data).find("item").each(function() {

            var item = $(this), title, description, thumbnail;

            title = item.find("title").text();
            description = item.find("description").text();
            thumbnail = item.find("img").attr("src");
        });
    }
});

PHP:

<?
header("content-type: text/xml");
readfile("http://api.flickr.com/services/feeds/photos_public.gne?id=42980910@N02&lang=en-us&format=xml");
?>

Edit: Mathews code works.
But I have a problem with appending some data.

    var currentImage = 0;
//get flicker images from rss.
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=42980910@N02&lang=en-us&format=json&jsoncallback=?", function(data) {
    $(data.items).each(function() {
        var item = this,
            title, description, thumbnail;
        title = item.title;
        description = item.description;
        thumbnail = item.media.m;
        if (currentImage % 3 === 0) {
            $("#apa").append("<p>HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH</p>");
        }
        currentImage++;
        $("#apa").append("<div id=\"div" + currentImage + "\" class=\"imageContainer pictDiv\"><img id=\"img" + currentImage + "\" class=\"bild pictImg\" src=\"" + thumbnail + "\" /></div>");
        $("#bakgrund").append("<img id=\"bkg" + currentImage + "\" class=\"bgrund pictBkg\" src=\"Bilder/polaroid.png\" />");
    });

    $("#bakgrund").append("<img id=\"bkg" + currentImage + "\" class=\"bgrund pictBkg\" src=\"Bilder/polaroid.png\" />");
});

This code works in Google Chrome. In Firefox it retrieves the data but don't do the append. If I try appending something else like simple text Firefox won't append that either.

It works when I'm trying it via jsfiddle.net but it doesn't when trying it via my own webpage.

  • 写回答

2条回答 默认 最新

  • douruhu4282 2010-11-17 21:55
    关注

    You can do this without PHP, using JSONP:

    $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=42980910@N02&lang=en-us&format=json&jsoncallback=?", function(data) {
            $(data.items).each(function() {
                var item = this, title, description, thumbnail;
                title = item.title;
                description = item.description;;
                thumbnail = item.media.m;
            });
        });
    

    I made a jsFiddle demo.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?