Ajax Blog 用到的几个函数第1/3页

时间:2021-05-28

类名:AJAX
复制代码 代码如下:


functionAJAX(){
varXMLHttp=false;
varObjSelf;
ObjSelf=this;
try{XMLHttp=newXMLHttpRequest;}
catch(e){
try{XMLHttp=newActiveXObject("MSXML2.XMLHttp");}
catch(e2){
try{XMLHttp=newActiveXObject("Microsoft.XMLHttp");}
catch(e3){XMLHttp=false;}
}
}
if(!XMLHttp)returnfalse;
this.method="POST";
this.url=""
this.url+=(this.url.indexOf("?")>=0)?"&nowtime="+newDate().getTime():"?nowtime="+newDate().getTime();
this.async=true;
this.data="";
ObjSelf.loadid=""
this.backtext=true
this.callback=function(){return;}

this.send=function(){
if(!this.method||!this.url||!this.async)returnfalse;
XMLHttp.open(this.method,this.url,this.async);
if(this.method=="POST"){
XMLHttp.setRequestHeader("Content-Length",(this.data).length);
XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}

XMLHttp.onreadystatechange=function(){
if(XMLHttp.readyState==4){
//alert(ObjSelf.loadid);
if(ObjSelf.loadid!="")$CS(ObjSelf.loadid,"none");
//window.status="";
if(XMLHttp.status==200){
ObjSelf.callback();
}
}
else{
if(ObjSelf.loadid!="")$CS(ObjSelf.loadid,"block");
//window.status="状态:["+XMLHttp.readyState+"]正在加载......";
}
}

if(this.method=="POST")XMLHttp.send(this.data);
elseXMLHttp.send(null);
}

this.gettext=function(){
if(XMLHttp.readyState==4){
if(XMLHttp.status==200){
if(this.backtext==true){
returnXMLHttp.responseText;
}else{
returnXMLHttp.responseXML;
}
}
}
}
}



blog.js
复制代码 代码如下:
//打开和关闭左栏
function$SHleft(id){
if($(id).style.display=='none'){
$(id).style.display='block';
$("content").style.width='550px';
$F("sh","隐藏左栏");
}
else{
$(id).style.display='none';
$("content").style.width='750px';
$F("sh","打开左栏");
}
}
//打开和关闭评论
function$PL(id,plid){
if($("rp"+id).style.display=='none'){
$("rp"+id).style.display='block';
$F("pl"+id,"隐藏评论");
replycon(id,"rp"+id);
}
else{
$("rp"+id).style.display='none';
$F("pl"+id,"查看评论");
}
}

//显示日志
functionshow(id,pageid,rq){
varajaxobj=newAJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=show&sid="+id+"&rq="+escape(rq)+"&page="+pageid;
ajaxobj.callback=function(){
$F("bkcon",ajaxobj.gettext());
}
ajaxobj.send();
}
//显示日志分类列表
functionboard(){
varajaxobj=newAJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=board";
ajaxobj.callback=function(){
$F("blogcon",ajaxobj.gettext());
}
ajaxobj.send();
}

//取得评论内容
functionreplycon(rid,rpid){
varajaxobj=newAJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=replycon&rid="+rid;
ajaxobj.callback=function(){
$F(rpid,ajaxobj.gettext());
}
ajaxobj.send();
}

//取得评论数量
functionplnum(rid){
varajaxobj=newAJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=plnum&rid="+rid;
ajaxobj.callback=function(){
$F("plnum"+rid,ajaxobj.gettext());
}
ajaxobj.send();
}

//加载发表评论表单
functionrform(rid){
varajaxobj=newAJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=rform&rid="+rid;
ajaxobj.callback=function(){
$F("plform"+rid,ajaxobj.gettext());
}
ajaxobj.send();
}

//添加评论内容
functionsavepl(rid){
varajaxobj=newAJAX();
ajaxobj.method="POST";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=savepl&";
ajaxobj.data="rid="+rid+"&username="+escape($("username"+rid).value)+"&con="+escape($("con"+rid).value);
ajaxobj.callback=function(){
$F("tjpl"+rid,ajaxobj.gettext());
if(ajaxobj.gettext().indexOf("评论已提交成功")>=0){
//如果评论提交成功则关闭表单、重新取得评论的数量。关闭成功提示信息
$CS("rform"+rid,"none");
plnum(rid);
pltjid="pltjsuc"+rid;
setTimeout('$CS(pltjid,"none")',1000);
}
}
ajaxobj.send();
}
//显示日历
functionrl(ReqDate){
varajaxobj=newAJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=rl&ReqDate="+ReqDate;
ajaxobj.callback=function(){
$F("calendarcon",ajaxobj.gettext());
}
ajaxobj.send();
}
//显示留言表单
functiongb(){
varajaxobj=newAJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=gb";
ajaxobj.callback=function(){
$F("gbform",ajaxobj.gettext());
}
ajaxobj.send();
}

//提交留言
functionsavegb(){
vargbusername=$("gbusername").value;
vargbemail=$("gbemail").value;
vargbcon=$("gbcon").value;
//alert($("gbusername").value);
//alert($("gbemail").value);
//alert($("gbcon").value);
//returnfalse;
if(gbusername==""){
$CS("gberr","block");
$F("gberr","请署上你的大名");
setTimeout('$CS("gberr","none")',2000);
returnfalse;
}
if(gbemail==""){
$CS("gberr","block");
$F("gberr","请写上你的邮箱");
setTimeout('$CS("gberr","none")',2000);
returnfalse;
}
if(gbcon==""){
$CS("gberr","block");
$F("gberr","请发表你的意见");
setTimeout('$CS("gberr","none")',2000);
returnfalse;
}
varajaxobj=newAJAX();
ajaxobj.method="POST";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=addgb&";
ajaxobj.data="username="+escape(gbusername)+"&email="+escape(gbemail)+"&con="+escape(gbcon);
ajaxobj.send();
ajaxobj.callback=function(){
if(ajaxobj.gettext().indexOf("成功")>=0){
$SHwin("gb");
showgb(1);
}
}
}
//显示留言
functionshowgb(pageid){
varajaxobj=newAJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=showgb&page="+pageid;
ajaxobj.callback=function(){
$F("bkcon",ajaxobj.gettext());
}
ajaxobj.send();
}

123下一页阅读全文

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章