欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PJBLOG中用到的ajaxjs.几个简单的函数

程序员文章站 2022-04-20 13:26:34
function $(id) {     return document.getelementbyid(id);...
function $(id)
{
    return document.getelementbyid(id);    
}
function echo(obj,html)
{
    $(obj).innerhtml=html;
}
function fopen(obj)
{
    $(obj).style.display="";
}
function fclose(obj)
{
    $(obj).style.display="none";
}
function createxmlhttp()
{
    var xmlhttp=false;
    try    {
          xmlhttp = new activexobject("msxml2.xmlhttp");
     } 
    catch (e) {
          try {
               xmlhttp = new activexobject("microsoft.xmlhttp");
          } 
        catch (e) {
               xmlhttp = false;
         }
     }
    if (!xmlhttp && typeof xmlhttprequest!='undefined') {
          xmlhttp = new xmlhttprequest();
                if (xmlhttp.overridemimetype) {//设置mime类别
            xmlhttp.overridemimetype('text/xml');
        }
    }    

    return xmlhttp;    
}

function getdata(url,obj1,obj2)
{

        var xmlhttp=createxmlhttp();
        if(!xmlhttp)
        {
            alert("你的浏览器不支持xmlhttp!!");
            return;
        }
        xmlhttp.onreadystatechange=requestdata;
        xmlhttp.open("get",url,true);
        xmlhttp.send(null);
        function requestdata()
        {

                fopen(obj1);
                echo(obj1,"正在加载数据,请稍等......");
                if(xmlhttp.readystate==4)
                {
                    if(xmlhttp.status==200)
                    {
                        if(obj1!=obj2){fclose(obj1);};
                        echo(obj2,xmlhttp.responsetext);

                    }
                }

        }
}