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

ajax.js里面有内容显示效果,根据ID

程序员文章站 2022-03-14 10:39:33
ajax.js里面有内容显示效果,根据id复制代码 代码如下:    var http_request =&nb...
ajax.js里面有内容显示效果,根据id
复制代码 代码如下:

    var http_request = false;
    var success=false;
    var showalllistflag=1;
    var displayarticle=true;
    function makerequest(url,cateid) {

        http_request = false;

        if (window.xmlhttprequest) { // mozilla, safari,...
            http_request = new xmlhttprequest();
            if (http_request.overridemimetype) {
                http_request.overridemimetype('text/xml');
            }
        } else if (window.activexobject) { // ie
            try {
                http_request = new activexobject("msxml2.xmlhttp");
            } catch (e) {
                try {
                    http_request = new activexobject("microsoft.xmlhttp");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('giving up :( cannot create an xmlhttp instance');
            return false;
        }
        http_request.onreadystatechange = alertcontents;
        http_request.open('get', url, false);
        http_request.send(null);
        if (success==true)
        {
            try {
                   cateid.innerhtml=http_request.responsetext;
                } catch (e) {}

            success==false;
        }

    }

    function alertcontents() {

        if (http_request.readystate == 4) {
            if (http_request.status == 200) {
                success=true;
            } else {
                alert('there was a problem with the request.');
            }
        }

    }

    function setcatlog(id,order,leftnumber) {

        var cateid=document.getelementbyid('cate'+id);
        setdisplay(cateid);
        if (cateid.style.display=="")
        {
        var url2="include/getsitelistfunction.asp?id="+id+"&order="+order+"&leftnumber="+leftnumber+"&r="+math.random();
        makerequest(url2,cateid);
        }
        else
        {
        var url2="include/getsitelistfunction.asp?id="+id+"&removeid=1&r="+math.random();
        makerequest(url2,cateid);
        }
    }

    function setarticlelist(encodeurl,articleid) {

        if (displayarticle==true)
        {
            try {  var objarticleidtop = document.getelementbyid('top'+articleid);
               var objarticleidbottom = document.getelementbyid('bottom'+articleid);
               if (objarticleidtop)
                  {
                    if  (objarticleidtop.style.display=="none")
                    {

                    objarticleidtop.style.display="";
                    }
                    else
                    {

                    objarticleidtop.style.display="none";
                    }
                  } 
                  if (objarticleidbottom)
                  {
                    if  (objarticleidbottom.style.display=="none")
                    {
                    var url2="include/getarticlefunction.asp?linkstr="+encodeurl+"&r="+math.random();
                    makerequest(url2,objarticleidbottom);
                    objarticleidbottom.style.display="";
                    }
                    else
                    {

                    objarticleidbottom.style.display="none";
                    }
                  } 

             } catch (e) {alert(e.description);}
        }
        else
        {
        }

    }


    function displaycontent(articleid) {

        if (displayarticle==true)
        {
            try {  var objarticleidtop = document.getelementbyid('top'+articleid);
               var objarticleidbottom = document.getelementbyid('bottom'+articleid);
               if (objarticleidtop)
                  {
                    if  (objarticleidtop.style.display=="none")
                    {

                    objarticleidtop.style.display="";
                    }
                    else
                    {

                    objarticleidtop.style.display="none";
                    }
                  } 
                  if (objarticleidbottom)
                  {
                    if  (objarticleidbottom.style.display=="none")
                    {

                    objarticleidbottom.style.display="";
                    }
                    else
                    {

                    objarticleidbottom.style.display="none";
                    }
                  } 

             } catch (e) {alert(e.description);}
        }
        else
        {
        }

    }

    function setdisplay(cateid) {
        if  (cateid.style.display=="none")
        {
        cateid.style.display="";
        cateid.innerhtml="loading..."
        }
        else
        {
        cateid.style.display="none";  
        }
    }

    function setdisplay2(cateid) {

        if (showalllistflag==1)
        {
          cateid.style.display="";
          cateid.innerhtml="loading..."
        }
        else
        {
          cateid.style.display="none";
        }
    }

    function showalllist(order,leftnumber,tagname)    {
        var obj = document.getelementsbytagname(tagname)

        for (a=0;a<obj.length;a++)
        {
            if (obj[a].classname=="sitelist")
            {
                obj2=obj[a].id;
                var id=obj2.replace("cate","");
                var cateid=document.getelementbyid(obj2);
                setdisplay2(cateid);
                if (cateid.style.display=="")
                {
                var url2="include/getsitelistfunction.asp?id="+id+"&order="+order+"&leftnumber="+leftnumber+"&r="+math.random();
                makerequest(url2,cateid);
                }
                else
                {
                var url2="include/getsitelistfunction.asp?id="+id+"&removeid=1&r="+math.random();
                makerequest(url2,cateid);
                }

            }

        }

        if (showalllistflag==1)
        {
            showalllistflag=2;
        }
        else
        {
            showalllistflag=1;
        }

    }

    function expandlistbysession(str,order,leftnumber) {
        try {
                var expandlist=str.split("|");

                for (b=0;b<expandlist.length-1;b++)
                {
                    setcatlog(expandlist[b],order,leftnumber)        
                }
             } catch (e) {}

    }