Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript http://www.engadget.com/rss.xml 没有响应我的XMLHttpRequest。控制台中没有错误代码_Javascript_Jquery_Google Chrome_Google Chrome Extension_Xmlhttprequest - Fatal编程技术网

Javascript http://www.engadget.com/rss.xml 没有响应我的XMLHttpRequest。控制台中没有错误代码

Javascript http://www.engadget.com/rss.xml 没有响应我的XMLHttpRequest。控制台中没有错误代码,javascript,jquery,google-chrome,google-chrome-extension,xmlhttprequest,Javascript,Jquery,Google Chrome,Google Chrome Extension,Xmlhttprequest,我正试图根据lifehacker的一个例子来做一个RSS阅读器chrome扩展(http://lifehacker.com/5857721/how-to-build-a-chrome-extension). 基于此,我自己做了。它不起作用。我尝试了他们的源代码,它工作得非常好(对于lifehacker),但当我更改xml源代码时,它只显示了一个空方块。如果有人能指出任何错误,我将非常感谢。我的文件是: manifest.json { "name": "RSS Fetcher", "v

我正试图根据lifehacker的一个例子来做一个RSS阅读器chrome扩展(http://lifehacker.com/5857721/how-to-build-a-chrome-extension). 基于此,我自己做了。它不起作用。我尝试了他们的源代码,它工作得非常好(对于lifehacker),但当我更改xml源代码时,它只显示了一个空方块。如果有人能指出任何错误,我将非常感谢。我的文件是:

manifest.json

  {
  "name": "RSS Fetcher",
  "version": "0.1",

  "description": "engadget rss reader.",
  "homepage_url": "http://www.engadget.com/",
    "background_page": "background.html",
    "permissions": [
      "<all_urls>",
      "http://www.engadget.com/*"


],
    "browser_action": {
    "default_title": "engadget reader",      
    "default_popup": "popup.html"       
  }
}
{
“名称”:“RSS抓取器”,
“版本”:“0.1”,
“说明”:“engadget rss阅读器”,
“主页地址”:http://www.engadget.com/",
“背景页面”:“background.html”,
“权限”:[
"';
项目+='';
$('弹出窗口')。追加(项目);
});
}
$(文档).ready(函数(){
fetch_feed();
});
parse.js

function parse_post(element) {
    // console.log(element);
    var post = new Object();
    post.title = $(element).find("title").text();
    post.tag = post.title.split('[')[1].split(']')[0];
    post.title = post.title.split('[')[0];
    post.id = $(element).find("guid").text();
    post.url = $(element).find('link').text();
    post.description = $("<div/>").html($(element).find("description")).text();
    post.img = $('img', post.description)[0].src; //107x60px
    var shorten = 120;
    if (post.title.length > 80) {
        shorten = 70;
    }
    post.description = $.trim($(post.description).text());
    post.description = post.description.substr(0, shorten);
    // console.log(post);
    return post;
}

function open_item(url) {
    chrome.tabs.create({url: url});
    chrome.browserAction.setBadgeText({text:''});
}
函数解析_post(元素){
//控制台日志(元素);
var post=新对象();
post.title=$(元素).find(“title”).text();
post.tag=post.title.split('[')[1]。split(']')[0];
post.title=post.title.split('[')[0];
post.id=$(元素).find(“guid”).text();
post.url=$(元素).find('link').text();
post.description=$(“”).html($(元素).find(“description”).text();
post.img=$('img',post.description)[0].src;//107x60px
var=120;
如果(post.title.length>80){
缩短=70;
}
post.description=$.trim($(post.description).text());
post.description=post.description.substr(0,缩短);
//控制台日志(post);
回程站;
}
函数打开项(url){
创建({url:url});
chrome.browserAction.setBadgeText({text:'});
}
我还使用了jquery-1.6.1.min.js 任何有帮助的地方:)提前谢谢!

不确定manifest.json中的“所有URL”是否有效,请删除它并尝试一下

<html>
<head>
    <script src='scripts/jquery-1.6.1.min.js'></script>
    <script src="scripts/parse.js"></script>
    <script>

        function fetch_feed() {
            chrome.extension.sendRequest({'action' : 'fetch_feed', 'url' : 'http://www.engadget.com/rss.xml'}, 
                function(response) {
                    display_stories(response);
                }
            );
        }

        function display_stories(feed_data) {
            var xml_doc = $.parseXML(feed_data);
            $xml = $(xml_doc);
            var items = $xml.find("item");
            $('#popup').html('<img src="images/logo.png" id="logo" onclick="open_item(\'http://engadget.com/\'); window.close();" /><br clear="all" />');
            items.each(function(index, element) {
                var post = parse_post(element);
                var item = '';
                var class2 = '';
                if (index >= localStorage['unread_count']) {
                    // // console.log('visited');
                    item += '<div class="post read">';
                }
                else {
                    item += '<div class="post">'
                }
                item += '<span class="tag">' + post.tag + '</span>\
                            <a href="' + post.url + '">\
                                <div id="' + post.id + '" class="item" onclick="open_item(\'' + post.url + '\');">\
                                    <img src="' + post.img + '" width="107" height="60" />\
                                    <h4>' + post.title + '</h4>\
                                    <span class="description">' + post.description + '...</span>\
                                </div>\
                            </a>';
                item += '</div>';
                $('#popup').append(item);
            });
        }

    </script>
    <link rel="stylesheet" href="styles/post.css" type="text/css" />
</head>
<body>

    <div id="popup">

    </div>
    <script>
        $(document).ready(function() {
            fetch_feed();
        });
    </script>
</body>
</html>
function parse_post(element) {
    // console.log(element);
    var post = new Object();
    post.title = $(element).find("title").text();
    post.tag = post.title.split('[')[1].split(']')[0];
    post.title = post.title.split('[')[0];
    post.id = $(element).find("guid").text();
    post.url = $(element).find('link').text();
    post.description = $("<div/>").html($(element).find("description")).text();
    post.img = $('img', post.description)[0].src; //107x60px
    var shorten = 120;
    if (post.title.length > 80) {
        shorten = 70;
    }
    post.description = $.trim($(post.description).text());
    post.description = post.description.substr(0, shorten);
    // console.log(post);
    return post;
}

function open_item(url) {
    chrome.tabs.create({url: url});
    chrome.browserAction.setBadgeText({text:''});
}