크로스 도메인 크롬 플러그인
I can't get this to work - I'm following the actual docs, as well as this example:
I'm simply trying to GET json data, formatted to the browser screen like so: {"name":"value"}, from a URL, but get a "null" value returned when I alert.
My manifest.json:
{ "name": "Chrome Extension", "version": "1.0", "description": "Does a GET request cross-domain.", "background_page": "plugin.html", "permissions": [ "tabs", "
http://*/*" ],
"browser_action": { "default_title": "", "default_icon": "icon.ico" }}
My plugin.html:
<html><head> <script> function fetchData(callback) { var req = new XMLHttpRequest(); req.onreadystatechange = function (data) { if (req.readyState == 4) { if (req.status == 200) { callback(req.responseText); } else { callback(null); } } }; var url = 'http://foo/bar.php'; req.open('GET', url, true); req.send(); }; function onRequest(request, sender, callback) { if (request.action == 'fetchData') { fetchData(callback); } }; chrome.extension.onRequest.addListener(onRequest); chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.create({url: 'index.html'}); }); </script></head></html>
My index.html:
<!DOCTYPE HTML><html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <script type="text/javascript"> function onReturn(data) { alert('Data ' + data); }; chrome.extension.sendRequest({'action' : 'fetchData'}, onReturn); </script> </body></html>
'IT노트 > 참고정보' 카테고리의 다른 글
IT기술 관련 도서 (0) | 2015.04.12 |
---|---|
안드로이드 웹서버 , NAS , 미디어 서버 만들기 웹서버 / Android (1) | 2015.03.21 |
게임이론이란? (0) | 2015.03.16 |
Application Service Provider. 응용소프트웨어 임대 (0) | 2015.03.16 |
공개 SW 라이센스 GPL, LGPL, BSD (0) | 2015.03.16 |