document.getElementById('id').src = reload not from cache

≡放荡痞女 提交于 2019-12-24 19:41:04

问题


i´ve a problem by reload elements not from cache.

Frist of all, my head:

<meta http-equiv="expires" content="0"><!-- no cache-->
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-store" />
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
<meta http-equiv="content-script-type" content="text/javascript">

So I´ve JavaScript var in external .txt documents written and changed by .php My task is to implement this var into HTML and keep them actual every 10 sec. I used following code:

<script type="text/javascript" id="Perso_UHS_1"></script>
<script>
    function reldataperso(){
    var dper = new Date();
    document.getElementById('Perso_UHS_1').src =
        "PersonalkapazitatUHS1.txt?time" + dper.getTime();
    };
    setInterval(function(){ 
        reldataperso();
        alert("test")
     }, 10000);
</script>
</head>
<body onload="reldataperso()">

OK, this works with .jpg oder .html but not by .txt in the head. The Browser don´t try to reload, by the alert was coming every 10 seconds...

Do you have any ideas?


回答1:


There are several issues that may be the cause of it.

  1. No semicolon after alert("test")
  2. The function reldataperso doesn't have a closing bracket (right before the </script> there should be a }.



回答2:


You have the 'cache-control' one wrong defined, maybe it fixes it

<meta http-equiv='cache-control' content='no-cache'>



来源:https://stackoverflow.com/questions/48911775/document-getelementbyidid-src-reload-not-from-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!