直接在 background.js
getPrice(); //直接运行
function handleError() {
}
function getPrice(){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4){
if(xhr.status==200){
//表示服务器端的响应代码是200,正确的返回了数据
//纯文本数据的接受方法
//var message=xmlhttp.responseText;
console.log(xhr.responseText);
}
}
};
xhr.open("GET", "http://demo.com", true);
xhr.send(null);
//console.error(xhr.response);
}
chrome.browserAction.setBadgeText({text:"1234"}); //插件icon添加文字
定时
var priceInterval = window.setInterval(function() {
self.getPrice();}, 30000);
}