2012-11-26 114 views
0

我有以下的AJAX脚本(包括chat.php和onload=online()<body> index.php),它显示了在线用户,并且在Firefox和Chrome中运行良好,但是当我尝试登录与IE8脚本不起作用。ajax脚本聊天用户bug即

任何人都可以帮我解决这个问题吗?也许AJAX脚本错误或与IE不兼容?

function online(){ 
    if (window.XMLHttpRequest){ 
     // code for IE7+, Firefox, Chrome, Opera, Safari 
     xmlhttp = new XMLHttpRequest(); 
    } 
    else{ 
     // code for IE6, IE5 
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 

    xmlhttp.onreadystatechange = function(){ 
     if (xmlhttp.readyState == 4 && xmlhttp.status == 200){ 
      document.getElementById("online").innerHTML = xmlhttp.responseText; 
     } 
    } 

    xmlhttp.open("GET","proses-chat.php"); 
    xmlhttp.send(); 
    setTimeout("online()", 8000); 
} 

function autofocus(){ 
    document.form_login.elements['username'].focus(); 
} 
+1

什么是错误,打F12,并期待在脚本/控制台。也强烈建议所有Ajax使用jQuery – mplungjan

+0

我同意mplungjan。以这种方式做你的AJAX是非常灰心的。看看http://api.jquery.com/category/ajax/ – IvanL

+0

也许这有助于:http://answers.microsoft.com/en-us/ie/forum/ie8-windows_7/xmlhttponreadystatechange-not-working -in -internet/e5aebea9-b1b3-48da-87f6-8c44e2731270?msgId = 85c6493a-8781-4722-b176-efc89a9ea7d8 显然,如果你收到一些非ascii字符,它会中断ie,所以你可能想尝试POST的GET。 – 2012-11-26 15:23:50

回答

0

在1天解决:d,这个问题是不是与AJAX脚本,但setcookies()

setcookie('username',$username,time()+36000,'http://$domain'); 
setcookie('password',$password,time()+36000,'http://$domain'); 
//$domain as define as $_SERVER['HTTP_HOST'] = localhost 

,以前是我在check_login.php饼干,最后IE和Safari didnt读取本地主机,我将其替换:

setcookie('username',$username,time()+3600,'/'); 
setcookie('password',$password,time()+3600,'/'); 

这意味着饼干接受所有的会议和地址及其对IE和Safari工作过:d,不要忘记消灭饼干

setcookie('username', '',time()-3600, '/'); 
setcookie('password', '',time()-3600, '/'); 

THX为所有的答复和建议之前,或许该解决方案可以帮助谁的人有问题,像我这样的THX