我要刷新網頁的一部分自動無需刷新整個頁面。 (說網頁的一個分部)。如何解決與Internet Explorer的Ajax自動刷新?
我有定期調用PHP頁面的腳本。
腳本:
<!----------- ********* AJAX code to auto refresh the part of a webpage************ --------->
<script langauge="javascript">
function loadXmlHttp(url, id) {
var f = this;
if (loadXmlHttp.xmlHttp){
f.xmlHttp = loadXmlHttp.xmlHttp();
f.el = document.getElementById(id);
f.xmlHttp.open("GET", url, true);
f.xmlHttp.onreadystatechange = function(){f.stateChanged();};
f.xmlHttp.send(null);
} else {
alert('Your browser does not support AJAX!');
}
}
loadXmlHttp.xmlHttp = null;
loadXmlHttp.re = /^http/.test(window.location.href);
/*@cc_on @*/ // used here and below, limits try/catch to those IE browsers that both benefit from and support it
/*@if(@_jscript_version >= 5) // prevents errors in old browsers that barf on try/catch & problems in IE if Active X disabled
try {loadXmlHttp.ie = window.ActiveXObject}catch(e){};
end @*/
if (window.XMLHttpRequest && (!loadXmlHttp.ie || loadXmlHttp.re))
loadXmlHttp.xmlHttp = function(){return new XMLHttpRequest();}; // Firefox, Opera 8.0+, Safari, others, IE 7+ when live - this is the standard method
else if (/(object)|(function)/.test(typeof createRequest))
loadXmlHttp.xmlHttp = createRequest; // ICEBrowser, perhaps others
else {
loadXmlHttp.xmlHttp = null;
// Internet Explorer 5 to 6, includes IE 7+ when local //
/*@if(@_jscript_version >= 5)
try{loadXmlHttp.xmlHttp = function(){return new ActiveXObject("Msxml2.XMLHTTP");};}
catch(e){try{loadXmlHttp.xmlHttp = function(){return new ActiveXObject("Microsoft.XMLHTTP");};}catch(e){}}
@end @*/
}
loadXmlHttp.prototype.stateChanged = function(){
if (this.xmlHttp.readyState == 4 && (this.xmlHttp.status == 200 || !loadXmlHttp.re)){
this.el.innerHTML = this.xmlHttp.responseText;
if(this.success){
this.success();
}
}
}
</script>
<!----------- ********* AJAX code to auto refresh the part of a webpage ends here************ --------->
我所在的地方調用這個函數一個DIV是這樣的:現在
<div class="textad" id="text"></div>
<script type="text/javascript">
(function(){
var statsrequest = new loadXmlHttp('display_text_ad.php', 'text'), repeat = arguments.callee;
statsrequest.success = function(){setTimeout(repeat, 6000);};
})();
</script>
</div>
,該代碼工作正常使用除了IE的所有瀏覽器。 (我已經檢查過Chrome,Mozilla,Opera和Safari)。所以,我需要一些幫助來修復Internet Explorer的這個bug。任何幫助將不勝感激。提前致謝。
它僅適用於第一次工作? –
在此先感謝所有幫助,即時通訊新的StackOverflow和即時消息它!任何想法/建議將不勝感激。請提供簡單的項目。所以任何人都可以對如何解決這個問題有任何想法?有沒有關於如何解決這個奇妙問題的建議?有任何想法嗎? – hakre
@FAngel我試圖調用PHP頁面「display_text_ad.php」。除了IE之外,它對所有瀏覽器都能正常工作。 –