1

My structure is shown below: enter image description here

My manifest.json is shown below:

{
"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"
}
}

My index.html is shown below:

<!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>

My config.json data(example data) is shown below:

{
"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"
            }
        }
    }
}
}

I want to get json data from my config.json. But how can i test this code to ensure that they are working. And do you think am i correct? Is this right way to get json value from locally?

ftdeveloper
  • 1,053
  • 3
  • 26
  • 50

1 Answers1

1

Before Chrome 29, the only way to retrieve the content of a file inside the extension package is XHR and this is the correct way.

As of Chrome 29, the new chrome.runtime.getPackageDirectoryEntry enables you to access files inside the package with HTML5 FileSystem API (See also http://www.html5rocks.com/en/tutorials/file/filesystem/, http://www.w3.org/TR/file-system-api/, https://developer.mozilla.org/en-US/docs/Web/API/DirectoryEntry).

However, the reason why your code doesn't work is pointed out by Rob W in the comment.

方 觉
  • 4,042
  • 1
  • 24
  • 28