[英]Chrome extension JSONP request access global variable
I'm using JSONP in a google chrome extension. 我在Google Chrome扩展程序中使用JSONP。 In order to make it work, i had to add
为了使其正常工作,我必须添加
chrome.extension.onRequest.addListener(onRequest);
and then make the request like this: 然后发出这样的请求:
var jsonpURL;
$(document).ready(function(){
/* i make the "someurl" here from a div's content */
jsonpURL="someurl";
chrome.extension.sendRequest({action:'getJSON',url:jsonpURL});
});
and the problem is, i cant acces the jsonpURL
variable in the request: 问题是,我无法在请求中
jsonpURL
变量:
function onRequest(request, sender, callback) {
alert(jsonpURL);
}
Undefinied. 不确定。
seems like the jsonpURL
variable has no value at the request despite i start it only after i gave value to the jsonpURL
variable in the ready function. 似乎
jsonpURL
变量在请求中没有任何值,尽管我仅在将ready函数中的jsonpURL
变量赋值后才启动它。
request.url应该与onRequest函数中的jsonpURL相等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.