[英]firefox addon main.js is showing same request response, not updating
What I'm doing wrong with addon builder? 我在Addon Builder上做错了什么? , it is not showing new request response, it show same response all the time, here is my code for main.js : ,它没有显示新的请求响应,而是一直显示相同的响应,这是我的main.js代码:
var tmr = require('timer');
var timus=5000;
var Request = require("sdk/request").Request;
function timer_restarting(){
gint = tmr.setInterval(function() {
Request({
url: "http://mysite.com/data.txt",
onComplete: function (response) {
if(response.text.indexOf('<show>true</show>')>-1){
timus = parseInt(response.text.substring(response.text.indexOf('<interval>')+10,response.text.indexOf('</interval>')));
show(response.text.substring(response.text.indexOf('<message>')+9,response.text.indexOf('</message>')));
tmr.clearInterval(gint);
timer_restarting();
}
}
}).get();
}, timus);
}
timer_restarting();
the addon show every 5 sec same message, it is not updating . 插件每5秒钟显示一次相同的消息,但不会更新。 I have an impression like it is not doing new request to server. 我有一个印象,好像它没有对服务器发出新请求。 I have changed message but it still show old message. 我已经更改了消息,但它仍然显示旧消息。 what is the issue? 有什么问题?
please 请
UPDATE: 更新:
if I will manually go to that link in browser and refresh it, then addon will refresh the respone as well. 如果我将手动在浏览器中转到该链接并刷新它,那么插件也将刷新响应。 Why is that happening ? 为什么会这样呢?
Try adding a header for ' Cache-control ' to your Request
instance, and specify a value of ' no-cache
' (or some ' max-age
' value), to prevent getting a cached response. 尝试将“ Cache-control ”的标头添加到您的Request
实例,并指定“ no-cache
”的值(或某些“ max-age
”的值),以防止获得缓存的响应。
Eg in your example, between the lines 例如在您的示例中
url: "http://mysite.com/data.txt",
onComplete: function (response) { /* ... */ }
insert the following lines: 插入以下行:
url: "http://mysite.com/data.txt",
headers: {
'Cache-control': 'no-cache'
},
onComplete: function (response) { /* ... */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.