0

私の最終的な目標は、RSS フィードを取得して、個人の Web サイトのホームページに表示するホームページを作成することです。これはすべてクライアント側から行われ、これを行うためのサーバー サイト スクリプトを作成するつもりはありません (他の方法が不可能な場合にのみ作成します)。

以下はページロードコードです。(これは問題のある領域ではないと思いますが、出発点を見るのはいいことです)

 $(document).ready(function () { // Here
    loadpageF(); //<- problems is in this function 
    GetBackGround(document.body); //this just messes with the css of the site
});

function loadpageF() {
    addTableFeed("http://www.npr.org/rss/rss.php?id=1001");
    addTableFeed("http://news.yahoo.com/rss/odd");
    addTableFeed("http://www.nfl.com/rss/rsslanding?searchString=team&abbr=DAL");
    addTableFeed("http://www.npr.org/rss/rss.php?id=1007");


    $(".MainArea").css("width",$("iframe").length * (270));

}
//This function sets up where the RSS data will be place after formatting
 function addTableFeed(feedlink) {

    var numOfCell = maintb.getElementsByTagName("iframe").length;


    maintb.innerHTML += "<iframe id='f" + numOfCell + "' class='iframeFeed'></iframe>";

    getRSSFeed(feedlink, "f" + numOfCell);

}

このコードは基本的に、追加する各 rss と iframe の関数を呼び出し、iframe id と URL を別の関数 (以下に示しますが、99% 確実に問題があると確信しています) に渡し、データを取得します。

 function getRSSFeed(feedlink, iframeid) {


     /*var xmlhttp; old way I did it below realizing it did not work in firefox

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
   xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

            var hold = xmlhttp.responseText
            loadData(hold, iframeid);
        }
    }
    xmlhttp.open("get", feedlink, false);
    xmlhttp.send();*/ //end of the old way

    //new way to try to use JSON of course failing at my in goal
    $.ajax({
        type: "GET",
        url: feedlink,
        async: true,
        dataType: "text",   

        success: function(data){
            loadData(data, iframeid);
        },
        error: function(data, statusCode) {
            alert("ERROR: "+data.error)
        }

    });}

関数 loadData は、呼び出されると問題なく動作しますが、Yahoo.com および NFL.com フィードに対しては呼び出されません。代わりに、以下に示すようなアラートが表示されます。

    //Note I has to transcribe from dialog box there may be errors
    ERROR: function () { 
    if( list ) {
        // First, we save the current length
        var start = list length;
        (function add( args ) {
            jQuery.each( args, function( _, arg ) {
                ¡f( jQuery.isFunction( arg ) && (!options unique || self.has( arg)
                    list .push( arg);
                else if( arg  && arg.length ) {
                    // Inspect recursively
                    add( arg);
                }
                });
            })( arguments);
            //Do we need to add the callbacks to the
            // current firing batch?
            if (firing ) (
                firingLength = list length;
            //wiIh memory, if we’re not firing then
            // we should call right away
            J else if ( memory ) (
                firingstart = start;
                fire( memory);

念のため、ロード データ コードを以下に示します。

function loadData(xml, ifid) {
    var htmlStr;
    var artCount = 0;

    var $xml = $($.parseXML(xml));
    $("#" + ifid)[0].contentDocument.open();
    $("#" + ifid)[0].contentDocument.close();
    $("#" + ifid)[0].contentDocument.write("<head><link rel='Stylesheet' type='text/css' href='" + document.getElementById("StyleSheet").href + "' /></head>");
    //RSS 2.0 handler
  $xml.find("channel item").each(function () {

        var $article = $(this);
        var title = $article.find("title").text();
        var description = $article.find("description").text();
        var link = $article.find("link").text();
        var pubDate = $article.find("pubDate").text();
        htmlStr = "<div id='" + artCount + "Span" + ifid + "' class='ArticalHead'><h3>" + title + "</h3></div>\n";
        htmlStr += "<div class='ArticalBody' id='" + artCount + "Div" + ifid + "'>\n";
        htmlStr += "\t<p>" + description + "</p><a href='" + link + "' target='_blank' > Click Here For more </a>\n";
        htmlStr += "\t<h6>" + pubDate + "</h6><br />\n";
        htmlStr += "</div>\n"


        $("#" + ifid)[0].contentDocument.write(htmlStr);

         $("#" + ifid).contents().find("#" +artCount + "Span" + ifid).click(function () {
             $("#" + ifid).contents().find("#" + $(this).attr("id").replace("Span", "Div")).toggle();
        });
        artCount++;
    });

    //Atom 1.0 handler
    $xml.find("feed entry").each(function () {

        var $article = $(this);
        var title = $article.find("title").text();
        var description = $article.find("summary").text();
        var link = $article.find("link").attr("href");
        var pubDate = $article.find("published").text();
        htmlStr = "<div id='" + artCount + "Span" + ifid + "' class='ArticalHead'><h3>" + title + "</h3></div>\n";
        htmlStr += "<div class='ArticalBody' id='" + artCount + "Div" + ifid + "'>\n";
        htmlStr += "\t<p>" + description + "</p><a href='" + link + "' target='_blank' > Click Here For more </a>\n";
        htmlStr += "\t<h6>" + pubDate + "</h6><br />\n";
        htmlStr += "</div>\n"


        $("#" + ifid)[0].contentDocument.write(htmlStr);

        $("#" + ifid).contents().find("#" + artCount + "Span" + ifid).click(function () {
            $("#" + ifid).contents().find("#" + $(this).attr("id").replace("Span", "Div")).toggle();
        });
        artCount++;
    });
    //$("#" + ifid).contents().find(".ArticalBody").hide();

}

誤字・脱字はご容赦ください。必要に応じて、Web ページ全体を投稿することもできます。

4

0 に答える 0