|
 |
|
ช่วยอธิบายและดูโค้ดเกี่ยวกับเวลาให้หน่อยค่ะ เป็น php JavaScript & Ajax |
|
 |
|
|
 |
 |
|
ช่วยอธิบายและดูโค้ดให้หน่อยค่ะ php&Ajax มันเป็นโค้ดเกี่ยวกับเวลาให้นับถอยหลัง เหมือนกับเว็ปประมูลสินค้า www.25satang.com แต่มันไม่นับถอยหลังให้อัติโนมัติ ทั้งที่ใช้ Ajax เข้ามาช่วย ต้องรีเฟรชหน้ามันถึงจะนับถอยหลังให้อ่ะค่ะ ช่วยหน่อยนะค่ะ
Code (PHP)
<script language="JavaScript1.2">
// update javascript timer by insert HTML tag into DOM document
// This file is combined between java script and PHP
function home_detail()
{
get_details('<?=$pids?>');
//more_product_detail();
}
function get_details(pids)
{
url= "<?=_BASEURL_?>/ajax_home_detail.php";
check_detail(url,pids);
}
function check_detail(strURL,pids) { //alert(pids);
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
//readystate == 4 it means the whole page is loaded, so we can call updatepage for timer insertion
updatepage(self.xmlHttpReq.responseText,pids);
}
}
self.xmlHttpReq.send(getquery(pids));
}
function getquery(pids) {
qstr = 'pids=' + pids ;
return qstr;
}
function updatepage(str,pids)
{
if(str==1)
{
<?
$parr = explode(",",$pids);
//explode set of product into individual product and calculate timer for each product.
for($a=0; $a < count($parr)-1;$a++)
{ ?>
document.getElementById("price_index_page_<?=$parr[$a]?>").style.background='';
document.getElementById("price_index_page_<?=$parr[$a]?>").innerHTML="" + document.frm.price_<?=$parr[$a]?>.value;
document.getElementById("winner_index_page_<?=$parr[$a]?>").innerHTML=document.frm.bider_<?=$parr[$a]?>.value;
if(document.frm.diff_<?=$parr[$a]?>.value!='')
{
differ_<?=$parr[$a]?> = document.frm.diff_<?=$parr[$a]?>.value;
if(differ_<?=$parr[$a]?> >= 1)
{
document.getElementById("button_finished_index_page_<?=$parr[$a]?>").style.display='';
document.getElementById("counter_index_page_<?=$parr[$a]?>").innerHTML=calc_counter_from_time22(differ_<?=$parr[$a]?>);
}
else
{
bid_ended(<?=$parr[$a]?>);
}
document.frm.diff_<?=$parr[$a]?>.value = "";
}
else
{
differ_<?=$parr[$a]?> = differ_<?=$parr[$a]?> - 1;
if(differ_<?=$parr[$a]?> >= 1)
{
document.getElementById("button_finished_index_page_<?=$parr[$a]?>").style.display='';
document.getElementById("counter_index_page_<?=$parr[$a]?>").innerHTML=calc_counter_from_time22(differ_<?=$parr[$a]?>);
}
else
{
bid_ended(<?=$parr[$a]?>);
}
}
<? } ?>
start_looping();
}
else
{
document.getElementById("product_detail").innerHTML = str;
<?
$parr = explode(",",$pids);
for($a=0; $a < count($parr)-1;$a++)
{ ?>
//alert('<?=$parr[$a]?>');
document.getElementById("price_index_page_<?=$parr[$a]?>").innerHTML="" + document.frm.price_<?=$parr[$a]?>.value;
document.getElementById("winner_index_page_<?=$parr[$a]?>").innerHTML=document.frm.bider_<?=$parr[$a]?>.value;
if(document.frm.new_<?=$parr[$a]?>.value == '1')
{
document.getElementById("winner_index_page_<?=$parr[$a]?>").style.background='#F6851F';
document.getElementById("winner_index_page_<?=$parr[$a]?>").style.color='#fff';
document.getElementById("price_index_page_<?=$parr[$a]?>").style.background='#cc0000';
document.frm.new_<?=$parr[$a]?>.value='0';
}
else
{
document.getElementById("winner_index_page_<?=$parr[$a]?>").style.background='';
document.getElementById("winner_index_page_<?=$parr[$a]?>").style.color='';
document.getElementById("price_index_page_<?=$parr[$a]?>").style.background='';
}
if(document.frm.diff_<?=$parr[$a]?>.value >= 1)
{
document.getElementById("button_finished_index_page_<?=$parr[$a]?>").style.display='';
document.getElementById("counter_index_page_<?=$parr[$a]?>").innerHTML=calc_counter_from_time22(document.frm.diff_<?=$parr[$a]?>.value);
}
else
bid_ended(<?=$parr[$a]?>);
<? } ?>
start_looping();
}
}
function start_looping()
{
setTimeout("get_details('<?=$pids?>')",200);
}
/*function more_product_detail()
{
<? $mpidarr=explode(",",$mpid);
$mdiffarr=explode(",",$mdiff);
for($w=0;$w < count($mpidarr)-1; $w++)
{ ?>
home_counter_<?=$mpidarr[$w]?>(<?=$mdiffarr[$w]?>);
<? } ?>
}
<? $mpidarr=explode(",",$mpid);
$mdiffarr=explode(",",$mdiff);
for($w=0;$w < count($mpidarr)-1; $w++)
{ ?>
function home_counter_<?=$mpidarr[$w]?>(diff)
{
timer=diff;
timer--;
document.getElementById("morecounter_<?=$mpidarr[$w]?>").innerHTML=calc_counter_from_time22(timer);
if(timer >1)
setTimeout("home_counter_<?=$mpidarr[$w]?>(" + timer + ")",1000);
else
home_bid_ended(<?=$mpidarr[$w]?>);
}
<? } ?>*/
</script>
Tag : PHP, JavaScript, Ajax

|
|
 |
 |
 |
 |
Date :
2010-11-21 14:24:51 |
By :
puisakura |
View :
868 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 00
|