我在使用插件生成器时做错了什么? ,它没有显示新的请求响应,它一直显示相同的响应,这是我的 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();
插件每 5 秒显示一次相同的消息,它没有更新。我的印象是它没有向服务器发出新请求。我已经更改了消息,但它仍然显示旧消息。有什么问题?
请
更新:
如果我手动转到浏览器中的那个链接并刷新它,那么插件也会刷新响应。为什么会这样?
最佳答案
尝试添加 header对于 ' Cache-control ' 到您的 Request
实例,并指定一个值 'no-cache
' (或一些 'max-age
' 值),以防止获取缓存的响应。
例如在你的例子中,在字里行间
url: "http://mysite.com/data.txt",
onComplete: function (response) { /* ... */ }
插入以下行:
url: "http://mysite.com/data.txt",
headers: {
'Cache-control': 'no-cache'
},
onComplete: function (response) { /* ... */ }
关于javascript - firefox 插件 main.js 显示相同的请求响应,而不是更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15905849/