Javascript 谷歌浏览器扩展。本地获取json数据

Javascript 谷歌浏览器扩展。本地获取json数据,javascript,json,google-chrome,google-chrome-extension,Javascript,Json,Google Chrome,Google Chrome Extension,我的结构如下所示: My manifest.json如下所示: { "manifest_version": 2, "name": "Doktor-MD", "description": "Tarayıcı üzerinden Doktor-MD'de link paylaşımı yapabilirsiniz.", "version": "1.0", "permissions": [ "http://www.google.com/" ], "browser_action": { "def

我的结构如下所示:

My manifest.json如下所示:

{
"manifest_version": 2,

"name": "Doktor-MD",
"description": "Tarayıcı üzerinden Doktor-MD'de link paylaşımı yapabilirsiniz.",
"version": "1.0",

"permissions": [
"http://www.google.com/"
],

"browser_action": {
"default_icon": "icon.png",
"default_popup": "index.html"
}
}
<!DOCTYPE html>
<html>
<head>  
<META http-equiv=content-type content=text/html;charset=utf8>
<META http-equiv=content-type content=text/html;charset=windows-1254>
<META http-equiv=content-type content=text/html;charset=x-mac-turkish>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">  </script>  
<script src="doktormdcore.js"></script>
<title>Doktor TV Md</title>
<script type="text/javascript">
    function GetDataFunction()
    {
        var xhr = new XMLHttpRequest();
        xmlHttpRequest.onreadystatechange = handleStateChange; //  Implemented elsewhere.
        xmlHttpRequest.open("GET",  chrome.extension.getURL('/config_resources/config.json'), true);
        xmlHttpRequest.send();
    }
</script>
</head>
<body>
    <table>
        <tr>
            <td>GetData</td>
            <td><input type="button" id="GetData" value="Getir"     onclick="GetDataFunction"/></td>
        </tr>
    </table>
</body>
</html>
{
"glossary": {
    "title": "example glossary",
    "GlossDiv": {
        "title": "S",
        "GlossList": {
            "GlossEntry": {
                "ID": "SGML",
                "SortAs": "SGML",
                "GlossTerm": "Standard Generalized Markup   Language",
                "Acronym": "SGML",
                "Abbrev": "ISO 8879:1986",
                "GlossDef": {
                    "para": "A meta-markup language, used to create markup languages  such as DocBook.",
                    "GlossSeeAlso": ["GML", "XML"]
                },
                "GlossSee": "markup"
            }
        }
    }
}
}
My index.html如下所示:

{
"manifest_version": 2,

"name": "Doktor-MD",
"description": "Tarayıcı üzerinden Doktor-MD'de link paylaşımı yapabilirsiniz.",
"version": "1.0",

"permissions": [
"http://www.google.com/"
],

"browser_action": {
"default_icon": "icon.png",
"default_popup": "index.html"
}
}
<!DOCTYPE html>
<html>
<head>  
<META http-equiv=content-type content=text/html;charset=utf8>
<META http-equiv=content-type content=text/html;charset=windows-1254>
<META http-equiv=content-type content=text/html;charset=x-mac-turkish>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">  </script>  
<script src="doktormdcore.js"></script>
<title>Doktor TV Md</title>
<script type="text/javascript">
    function GetDataFunction()
    {
        var xhr = new XMLHttpRequest();
        xmlHttpRequest.onreadystatechange = handleStateChange; //  Implemented elsewhere.
        xmlHttpRequest.open("GET",  chrome.extension.getURL('/config_resources/config.json'), true);
        xmlHttpRequest.send();
    }
</script>
</head>
<body>
    <table>
        <tr>
            <td>GetData</td>
            <td><input type="button" id="GetData" value="Getir"     onclick="GetDataFunction"/></td>
        </tr>
    </table>
</body>
</html>
{
"glossary": {
    "title": "example glossary",
    "GlossDiv": {
        "title": "S",
        "GlossList": {
            "GlossEntry": {
                "ID": "SGML",
                "SortAs": "SGML",
                "GlossTerm": "Standard Generalized Markup   Language",
                "Acronym": "SGML",
                "Abbrev": "ISO 8879:1986",
                "GlossDef": {
                    "para": "A meta-markup language, used to create markup languages  such as DocBook.",
                    "GlossSeeAlso": ["GML", "XML"]
                },
                "GlossSee": "markup"
            }
        }
    }
}
}

我想从config.json中获取json数据。但是如何测试这些代码以确保它们正常工作呢。你认为我说的对吗?这是从本地获取json值的正确方法吗?

在Chrome 29之前,检索扩展包内文件内容的唯一方法是XHR,这是正确的方法

从Chrome 29开始,新版本允许您使用HTML5文件系统API访问包内的文件(另请参见)


然而,Rob W在评论中指出了代码不起作用的原因。

在Chrome 29之前,检索扩展包内文件内容的唯一方法是XHR,这是正确的方法

从Chrome 29开始,新版本允许您使用HTML5文件系统API访问包内的文件(另请参见)

然而,Rob W在评论中指出了代码不起作用的原因