我有一個div,我每1秒用Ajax重新加載一次。並且它具有溢出的自動值。爲了讓我的div始終保持最低,我在Ajax請求中使用了一個JavaScript代碼。不可選擇的Ajax內容
xmlHttp.onreadystatechange=function(){
document.getElementById('chatting').scrollTop = 9999999;
if(xmlHttp.readyState==4){
document.getElementById('chatting').innerHTML=xmlHttp.responseText;
setTimeout('Ajax()',1000);
}
}
var withdate=document.getElementById('firstdate').value;
nocache = Math.random();
xmlHttp.open("GET","db.getMessages.php?date=" + withdate + "&nocache = "+nocache,true);
xmlHttp.send(null);
}
window.onload=function(){
setTimeout('Ajax()',1000);
}
但我不能選擇文本,也不能上去。當新內容加載時,div滑動到底部。我該如何解決這個問題?
我也有問題。我正在使用PHP文件來定義json內容。而輸出是這樣的:
{ "msg": [{"from":"demo","text":"test message "} ] }
但Firebug的顯示了這個錯誤對我說:
錯誤:JSON.parse:意外的字符 源文件:http://localhost/script/script/json.js 線:20
線20是:
var msgs = JSON.parse(xhr.responseText);
我奮鬥了這麼多,但還沒有解決:(
它看起來不太「jQuery」 – gdoron 2012-02-18 22:15:42