Ajax Blog 用到的几个函数第1/3页
Ajax Blog 用到的几个函数第1/3页
发布时间:2016-12-30 来源:查字典编辑
摘要:类名:AJAX复制代码代码如下:/*类名:AJAX创建方法:varajaxobj=newAJAX;,如果创建失败则返回false属性:met...

类名:AJAX

复制代码 代码如下:

/*类名:AJAX

创建方法:varajaxobj=newAJAX;,如果创建失败则返回false

属性:method-请求方法,字符串,POST或者GET,默认为POST

url-请求URL,字符串,默认为空

async-是否异步,true为异步,false为同步,默认为true

content-请求的内容,如果请求方法为POST需要设定此属性,默认为空

backtext-默认true当backtext=true时返回XMLHttp.responseText为false时返回XMLHttp.responseXML

gettext-返回值

callback-回调函数,即返回响应内容时调用的函数,默认为直接返回,回调函数有一个参数为XMLHttpRequest对象,即定义回调函数时要这样:functionmycallback(xmlobj)

方法:send()-发送请求,无参数

*/

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();

}

当前1/3页123下一页阅读全文

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类