简体   繁体   中英

Not working in Internet explorer?

I have this script, which is running fine across all browsers except internet explorer. Essentially this script is refreshing the page to display the chat. Any suggestions ?

Could I get it to refresh every so often if just in internet explorer ?

function ajax(){

var req = new XMLHttpRequest();

req.onreadystatechange = function(){

if(req.readyState == 4 && req.status == 200){

document.getElementById('chat').innerHTML = req.responseText;
} 
}
req.open('GET','chat.php',true); 
req.send();

}
setInterval(function(){ajax()},1000);

On old versions of IE you need window.ActiveXObject ( http://blog.blackbam.at/2012/02/07/basic-ajax-skeleton-code/ )

var XMLHTTP = null;

function AjaxRequest(compString) {

// XMLHTTP-Request Objekt erzeugen, dabei auf Browserkonformität achten
 if(window.XMLHttpRequest) {
  XMLHTTP = new XMLHttpRequest();
 } else if(window.ActiveXObject) {
  try {
   XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
  } catch(ex) {
   try {
    XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
   } catch(ex) {
   }
  }
 }

 XMLHTTP.open("GET","test.php?compString="+compString);
 XMLHTTP.onreadystatechange = MyRequestExecute;
 XMLHTTP.send(null);
}

// wird jedes mal aufgerufen, wenn der XMLHTTP-Request eine neue Stufe erreicht, bei 4 ist die Antwort des Servers eingetroffen
function MyRequestExecute() {
 // responseText als Javascript-String, responseXML als Javascript XML-DOM-Element, status Statuscode, statusText des. Beschreibung
 if(XMLHTTP.readyState == 4) {
  document.getElementById("result").innerHTML = XMLHTTP.responseText;
 }
}

use Jquery instead of Javascript

Like this:

$.ajax({
       url:"chat.php",
       type:"get",
       success:function(responseText){
            document.getElementById('chat').innerHTML = responseText;
        }
       })

This not be an answer. Adding to get idea about Support

XMLHttpRequest Is not support in old IE.

IE Supports

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM