看板 Web_Design 關於我們 聯絡資訊
※ 引述《sicao (adios)》之銘言: : 底下的程式碼是在網路上抄來的 : 在Firefox上 : 只要更新autoupdate.txt內容就會更新 : 但Chrome反應就沒那麼快 要等一陣子才會更新 : IE卻一直緊咬舊資料不更新 : 即使重新整理也一樣 : 請問我該怎麼修正?? : <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> : <META HTTP-EQUIV="expires" CONTENT="0"> : <META HTTP-EQUIV="pragma" CONTENT="no-cache"> : <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"> : <html> : <head> : <title></title> : <script type="text/javascript" language="javascript"> function makeRequest(url,callback) { if(!url) return; if(!callback) return; var http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } http_request.onreadystatechange = function () { if (http_request.readyState == 4 && http_request.status == 200) { callback(http_request); }; http_request.open('GET', url.indexOf("?") ? url + "&random=" + Math.round(Math.random * 1000) : url + "?=" + Math.round(Math.random * 1000) , true); http_request.send(null); } function alertContents(http_request) { document.getElementById("up").innerHTML = http_request.responseText; //alert('1'); //alert(http_request.responseText); } function MyShow(url,callback) { //2秒自?刷新一次,2秒取得一次?据. timer = window.setInterval(function () { makeRequest(url,callback); }, 2000); } : </script> : </head> <body onload="MyShow('autoupdate.txt', alertContents)"> <span style="cursor: pointer; text-decoration: underline" onclick=""> Make a request </span> : <div id="up"></div> : </body> : </html> --
Skightz:回文推下面就輸了09/05 14:27
s25g5d4:下面09/05 14:28
tmi: 變竹籤09/05 14:39
ArSaBuLu:Oh My God! 我的下面酥了...怎麼辦?09/05 14:43
ilovedandan:真的耶 我都沒發現耶XDDDD 超像的!!!09/05 14:47
Skightz:樓上之前都沒發現自己的變竹籤,真的超像竹籤的09/05 15:33
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.219.244 @@" 請原諒我昨天神智不清就發文... 加上url與callback檢查 還有最重要的url後的random函數... 其他作法是 url後面加上時間 不過我是比較喜歡用random ※ 編輯: s25g5d4 來自: 59.116.103.217 (12/15 07:26)