Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62225
  • 博文数量: 5
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-27 22:24
文章分类

全部博文(5)

文章存档

2011年(1)

2008年(4)

我的朋友
最近访客

分类: 系统运维

2008-03-11 17:32:44

现在AJAX很火,对于我们菜鸟来说比较难搞定。
今天写了个简单的程序,提供給大家参考!
有问题可以EMAIL我,呵呵
E-mail:qsbaq [at] 163.com


AJAX.JS

function ajaxSend(url,changeObjId, formAction)
{
    var objId = changeObjId;
    var xmlHttp = false;
    if(window.ActiveXObject)
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if(window.XMLHttpRequest)
    {
        xmlHttp = new XMLHttpRequest();
    }

    if (xmlHttp)
    {
        xmlHttp.open(formAction, url, true);
        if(!changeObjId=="")
        {
            xmlHttp.onreadystatechange = function()
            {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
                {
                    document.getElementById(changeObjId).innerHTML = xmlHttp.responseText;
                    delete xmlHttp;
                    xmlHttp = null;
                }
            }
        }
        xmlHttp.send(null);    
    }
}


下面贴出调用页面的部分代码,即结果页面

<script src="js/ajax.js"></script>
<script>
function showVotes($code){
    ajaxSend("ajaxnum.php?code="+$code,$code,"POST");
}
</script>

id);$j++)   
    {   
        $seriesDetail=getDetailBySeriesId(getSeriesById($i,'series')->id);
        $tohtml = "htmls/".$i.($j+1).".html";
        $code = "P".$i.'-'.($j+1);
        $img=$seriesDetail[$j]->bgimg;
        $imgsize = getimagesize($seriesDetail[$j]->bgimg);
        $simg = $seriesDetail[$j]->img;
        if($imgsize[0]>=$imgsize[1])
        {
            $toW=200;
            $toH=139;
        }
        else
        {
            $toW=$imgsize[0]*139/$imgsize[1];
            $toH=139;
        }
        if(!file_exists($simg)){
            if(!$imageTreat->ImageResize($img, $toW, $toH,$simg))
                print_r($img."===>".$toW.'*'.$toH."   To   ".$simg."==========> Failed ");
        }       
?>
   
 


   
       
       
       
       
P name?>
目前有人投票!

     




ajaxnum.php

<?
    require_once('conn.inc.php');
    $sql = "select code from `voteMgr` where code = ".'"'.trim($_REQUEST['code']).'"';
    $res=mysql_query($sql) or die(mysql_error());
    echo mysql_num_rows($res);            //要打印出来的,不要return
?>


这样它就会每10秒钟更新一次投票结果的数值!
其实很简单的啦!

大家可以把代码自己封装一下,就可以用啦!
阅读(2542) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-01-09 11:41:13

dsfdsf