2012-11-26 37 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