1
저는 Chrome 용 플러그인을 프로그래밍하고 있습니다. 문제는 jQuery $ .get 호출을 사용할 수 없다는 것입니다. 콘솔 말한다 : 리소스를로드하지 못했습니다.
//popup.html
<script>
_get = function(url, callback) {
console.log("sending get");
chrome.extension.sendRequest({action:'get',url:url}, callback);
}
_get('https://www.meebo.com/mcmd/start.cgi?type=mobile&allowIPChange=true', function(data) {
alert(data);
});
</script>
//background.html
<script src="jquery.js"></script>
<script type="text/javascript">
function onRequest(request, sender, callback) {
if (request.action == 'getJSON') {
$.getJSON(request.url, callback);
}
if (request.action == 'ajax') {
$.ajax({
type : request.type,
url : request.url,
async : async,
success : callback
});
}
if (request.action == 'get') {
$.get(request.url, callback);
}
if (request.action == 'post') {
$.post(request.url, request.data, callback);
}
}
chrome.extension.onRequest.addListener(onRequest);
</script>
흠, 부품 연결 방법을 설명해 주시겠습니까? 당신은 분명히 요청을 수행하는 두 가지 다른 방법 (크롬 내장 및 jquery)을 사용하고 있습니다. 첫 번째 스 니펫은 문제와 어떤 관련이 있습니까? – moritz
문제는 크롬의 보안 제한 때문에 콘텐츠 파일에서 jQuery-ajax-functions을 사용할 수 없다는 것입니다. 따라서 popup.html에서 ajax 요청을 수행하고 있는데 chrome.extension.sendRequest ({ action : 'get', url : url}, 콜백); 그들은 background.html에서 chrome.extension.onRequest.addListener (onRequest); backgroundpages에는 제한이 없기 때문에 실행됩니다. 실패한 부분은 $ .get (request.url, callback); 함수가 호출되었지만 결과가 콘솔 출력입니다. "자원로드 실패" –