簡體   English   中英

firefox插件main.js顯示相同的請求響應,未更新

[英]firefox addon main.js is showing same request response, not updating

我在Addon Builder上做錯了什么? ,它沒有顯示新的請求響應,而是一直顯示相同的響應,這是我的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秒鍾顯示一次相同的消息,但不會更新。 我有一個印象,好像它沒有對服務器發出新請求。 我已經更改了消息,但它仍然顯示舊消息。 有什么問題?

更新:

如果我將手動在瀏覽器中轉到該鏈接並刷新它,那么插件也將刷新響應。 為什么會這樣呢?

嘗試將“ 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) { /* ... */ }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM