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

asp实现dig功能的js代码

程序员文章站 2022-05-28 16:38:58
//ajax 控件 function diggajax(){     var xhrobj=null;...
//ajax 控件
function diggajax(){
    var xhrobj=null;
    if(window.xmlhttprequest){
        xhrobj=new xmlhttprequest();
    }
    else if(window.activexobject){
    try{
    xhrobj=new activexobject("microsoft.xmlhttp");
    }
    catch(e1)
    {
    try{
    xhrobj=new activexobject("msxml2.xmlhttp");
    }
    catch(e2){
    try{
    xhrobj=new activexobject("msxml3.xmlhttp");
    }
    catch(e3){
    alert("创建ajax失败:"+e3)
    }
    }
    }
    }
    else
    {
    alert("未能识别的浏览器");
    }
    return xhrobj;
}
var loader=new diggajax;
function ajaxloadpage(url,request,method,fun)

    method=method.touppercase();
    if (method=='get')
    {
        urls=url.split("?");
        if (urls[1]=='' || typeof urls[1]=='undefined')
        {
            url=urls[0]+"?"+request;
        }
        else
        {
            url=urls[0]+"?"+urls[1]+"&"+request;
        }

        request=null;
    }
    loader.open(method,url,true);
    if (method=="post")
    {
        loader.setrequestheader("content-type","application/x-www-form-urlencoded");
    }
    loader.onreadystatechange=function(){
         eval(fun+'()');
    }
    loader.send(request);
 }
 function callbacks()
  {
  if (loader.readystate==4)
  {
    var s=loader.responsetext;
    switch (s)
    {
        case "err":
         alert('digg error!');
         break;
        case "over":
         alert('你已推荐过了!');
         break;
        case "nologin":
          alert('您还没有登录,不能推荐!');
          break;
        default:
           var sarr=s.split('|');
           eval("document.all.s"+sarr[0]).innerhtml=sarr[1];
           eval("document.all.d"+sarr[0]).innerhtml="thanks";

    }

    }
  }


//digg
function digg(channelid,infoid,installdir)
{
  ajaxloadpage(installdir+'plus/digg.asp','action=hits&channelid='+channelid+'&infoid=' +infoid,'post','callbacks');

}
function show_digg(channelid,infoid,installdir)

   var xhr=new diggajax();
   xhr.open("get",installdir+"plus/digg.asp?channelid="+channelid+"&infoid="+infoid+"&action=show",true);
   xhr.onreadystatechange=function (){
             if(xhr.readystate==1)
              {
                eval("document.all.s"+infoid).innerhtml="<img src='"+installdir+"images/loading.gif'>";
              }
              else if(xhr.readystate==2 || xhr.readystate==3)
              {
                eval("document.all.s"+infoid).innerhtml="<img src='"+installdir+"images/loading.gif'>";
              }
              else if(xhr.readystate==4)
              {
             if (xhr.status==200)
             {   
                  var r=xhr.responsetext
                  var rarr=r.split('|');
                  eval("document.all.s"+infoid).innerhtml=rarr[1];
             }
            }
       }
    xhr.send(null);  
}