2013-07-22 5 views
0

내 구조는 다음과 같습니다하기 : enter image description hereGoogle 크롬 확장 프로그램. JSON 데이터는 로컬

내의 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" 
} 
} 

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

내 설정을 .json 데이터 (예제 데이터)는 다음과 같습니다.

{ 
"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 값을 얻으려면이 올바른 방법입니까?

+0

도움 주셔서 감사합니다. – fuat

답변

1

Chrome 29 이전 버전에서는 확장 패키지 내의 파일 내용을 검색하는 유일한 방법은 XHR이며 올바른 방법입니다. 크롬 29로

는, 새로운 chrome.runtime.getPackageDirectoryEntry 당신이 HTML5 파일 시스템 API와 함께 패키지 내부의 파일에 액세스 할 수 있습니다 (또한 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 참조).

그러나 코드가 작동하지 않는 이유는 Rob W가 주석에서 지적한 것입니다.

+0

도움 주셔서 감사합니다. – fuat