|
 |
|
แปลโค้ดนี้ให้ที index-ajax.php?isAction คือ contents คือ scrollTop คือ scrollHeight คือ |
|
 |
|
|
 |
 |
|
เหมือนจะเป็นโค้ด chat ครับ
index-ajax.php?isAction=refresh คือ ตำแหน่งไฟล์ที่จะดึงข้อมูลมาแสดงครับ isAction=refresh ก็คือตัวแปร $_GET['isAction'] มีค่า 'refresh'
contents คือ id ของ html tag อย่างเช่น <div id="contents"></div> ซึ่งจะโหลดข้อมูลจาก index.ajax.php มาแสดงครับ
scrollTop คือ ตำแหน่งของ scrollbar
scrollHeight คือ ตำแหน่งสูงสุดของ scrollbar ถ้า scrollTop = scrollHeight scrollbar จะอยู่ล่างสุดครับ
|
 |
 |
 |
 |
Date :
2009-11-08 10:38:55 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
var HttPRequest = false;
function chat() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = '../chatroom/AjaxPHPChat2.php';
var pmeters = "tName=" + encodeURI( document.getElementById("txtName").value) +
"&tMessage=" + encodeURI( document.getElementById("txtMessage").value );
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById('mySpan').innerHTML = HttPRequest.responseText;
// focus //
var el = document.getElementById('mydiv');
el.tabIndex = 32456;
el.focus();
}
}
}
function show_message()
{
var fileName = 'index-ajax.php?isAction=refresh';
new Ajax(fileName , { method: 'get', onComplete: isRefresh , update: 'contents'}).request();
$('contents').scrollTop = $('contents').scrollHeight;
function isRefresh() {
setTimeout("show_message()", 7000);
$('contents').scrollTop = $('contents').scrollHeight;
}
โค้ดเต็มๆ (จาวา)
รีเฟรชไม่ได้สักทีอ่ะ แก้จะแย่แล้ว T-T
|
 |
 |
 |
 |
Date :
2009-11-08 11:46:59 |
By :
gawalins |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีโค้ดแค่นี้หาจุด error ยากครับ
ใช้ firefox + firebug แล้วเปิด firebug console ทดสอบเว็บดูครับ จะมี error โชว์ให้เห็นง่ายขึ้นครับ
http://getfirebug.com/
|
 |
 |
 |
 |
Date :
2009-11-08 13:56:33 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|