来自chinaz的ajax获取评论代码

2018-10-15 18:06

阅读:800

ajax获取到的字符是类似下面的内容
复制代码 代码如下:
{a:<divclass=pl_list><div><spanclass=float_right><ahref=javascript:goodbad(22835,26769,good,1)title=支持一下>支持:[0]</a><ahref=javascript:goodbad(22835,26769,bad,1)title=我反对>反对:[0]</a></span><spanclass=zz>中国站长站网友:匿名于2008-04-25评论道:</span></div>谁认为投放了GoogleAdSense的站点就不允许进行推广了?傻子吧</div>,b:1}

然后用下面的ajax进行输出
复制代码 代码如下:

varkey=;
varstr=newArray();

functioncreateAjaxObj(){
varhttprequest=false
if(window.XMLHttpRequest){//ifMozilla,Safarietc
httprequest=newXMLHttpRequest()
if(httprequest.overrideMimeType)
httprequest.overrideMimeType(text/xml);
}
elseif(window.ActiveXObject){//ifIE
try
{
httprequest=newActiveXObject(Msxml2.XMLHTTP);
}
catch(e)
{
try
{
httprequest=newActiveXObject(Microsoft.XMLHTTP);
}
catch(e){}
}
}
returnhttprequest;
}

functionload_feedback(arcID,pg){

/*
varurl=
varajax=newoAjax();
//是否显示错误
//ajax.error=true;
//请求的页面的编码为gb2312或空
//ajax.encode=gb2312;
//回调函数
ajax.callback=function(content){
//处理返回内容
eval(varobj=+content);
document.getElementById(fedcount).innerHTML=obj.b;
};
ajax.send(url);
*/

varxmlhttp=createAjaxObj();
try
{

varparams=action=show&arcID=+arcID+&pg=+pg;
xmlhttp.abort();

xmlhttp.open(get,/plus/feedback_ajax.php?+params,true);

xmlhttp.setRequestHeader(Content-type,text/html;charset=gb2312);

xmlhttp.setRequestHeader(If-Modified-Since,0);

xmlhttp.setRequestHeader(Content-length,params.length);

xmlhttp.setRequestHeader(Connection,close);

xmlhttp.onreadystatechange=f

xmlhttp.send(null);

}catch(ex){}
functionf()
{

if(xmlhttp.readyState!=4xmlhttp.status!=200)
return;
varb=xmlhttp.responseText;
varobj=eval((+b+));
document.getElementById(fedbk).innerHTML=obj.a;
document.getElementById(fedcount).innerHTML=obj.b;
document.getElementById(feedcounttop).innerHTML=obj.b;
}
}


functionload_allfeedback(arcID,pg){

varxmlhttp=createAjaxObj();
try
{

varparams=action=showall&arcID=+arcID+&pg=+pg;
xmlhttp.abort();

xmlhttp.open(get,/plus/feedback_ajax.php?+params,true);

xmlhttp.setRequestHeader(Content-type,text/html;charset=gb2312);

xmlhttp.setRequestHeader(If-Modified-Since,0);

xmlhttp.setRequestHeader(Content-length,params.length);

xmlhttp.setRequestHeader(Connection,close);

xmlhttp.onreadystatechange=f

xmlhttp.send(null);

}catch(ex){}
functionf()
{

if(xmlhttp.readyState!=4xmlhttp.status!=200)
return;
varcontent=xmlhttp.responseText;
varobj=eval((+content+));
//eval(varobj=+content);
document.getElementById(fedbk).innerHTML=obj.a;
//document.getElementById(fedcount).innerHTML=obj.b;
}
}

functionfeed_back(){

varmsg=trim(document.getElementById(msg).value);
vararcID=document.getElementById(arcID).value;
varusername=trim(document.getElementById(username).value);
varpwd=trim(document.getElementById(pwd).value);
varcheckbox=document.getElementById(notuser);
if(checkbox.checked)
varnotuser=1;
else
varnotuser=0;


varxmlhttp=createAjaxObj();
try
{

params=action=send&arcID=+arcID+&msg=+msg+&username=+username
+&pwd=+pwd+&notuser=+notuser;

xmlhttp.abort();

xmlhttp.open(get,/plus/feedback_ajax.php?+params,true);

xmlhttp.setRequestHeader(Content-type,text/html;charset=gb2312);

xmlhttp.setRequestHeader(If-Modified-Since,0);

xmlhttp.setRequestHeader(Content-length,params.length);

xmlhttp.setRequestHeader(Connection,close);

xmlhttp.onreadystatechange=f

xmlhttp.send(null);

}catch(ex){}
functionf()
{
if(xmlhttp.readyState!=4xmlhttp.status!=200)
return;
vararr=xmlhttp.responseText.split(@:);

if(!arr[1]){
alert(xmlhttp.responseText);
}
else{
if(arr[0]!=true)
alert(arr[0]);
alert(arr[2]);
ck_yzimg();
load_feedback(arr[1],1);
}
}

}

functiongoodbad(fid,arcid,actname,pg){


varxmlhttp=createAjaxObj();

try
{
params=action=+actname+&fid=+fid+&arcID=+arcid+&pg=+pg;

xmlhttp.abort();

xmlhttp.open(get,/plus/feedback_ajax.php?+params,true);

xmlhttp.setRequestHeader(Content-type,text/html;charset=gb2312);

xmlhttp.setRequestHeader(If-Modified-Since,0);

xmlhttp.setRequestHeader(Content-length,params.length);

xmlhttp.setRequestHeader(Connection,close);

xmlhttp.onreadystatechange=f

xmlhttp.send(null);

}catch(ex){}
functionf()
{
if(xmlhttp.readyState!=4xmlhttp.status!=200)
return;
vararr=xmlhttp.responseText.split(@:);

if(!arr[1])
alert(xmlhttp.responseText);
else{
alert(arr[0]);
load_feedback(arr[1],arr[2]);
}
}

}

functiongoodbad2(fid,arcid,actname,pg){


varxmlhttp=createAjaxObj();

try
{
params=action=+actname+&fid=+fid+&arcID=+arcid+&pg=+pg;

xmlhttp.abort();

xmlhttp.open(get,/plus/feedback_ajax.php?+params,true);

xmlhttp.setRequestHeader(Content-type,text/html;charset=gb2312);

xmlhttp.setRequestHeader(If-Modified-Since,0);

xmlhttp.setRequestHeader(Content-length,params.length);

xmlhttp.setRequestHeader(Connection,close);

xmlhttp.onreadystatechange=f

xmlhttp.send(null);

}catch(ex){}
functionf()
{
if(xmlhttp.readyState!=4xmlhttp.status!=200)
return;
vararr=xmlhttp.responseText.split(@:);

if(!arr[1])
alert(xmlhttp.responseText);
else{
alert(arr[0]);
load_allfeedback(arr[1],arr[2]);
}
}

}

functionpg(vl){
vararcID=document.getElementById(arcID).value;
load_feedback(arcID,vl);
}
functionpg2(arcID,vl){
//vararcID=document.getElementById(arcID).value;
load_allfeedback(arcID,vl);
}
functionck_yzimg(){
//document.all.cknum.value=;
document.all.msg.value=;
document.all.pwd.value=;
document.getElementsByName(sb)[0].disabled=false;
//document.all.img1.onclick();
}

functiontrim(s){
returns.replace(/^\s*/,).replace(/\s*$/,);

}

//////
/*
return(this.indexOf(str)>-1);
};
varBrowser={
s:navigator.userAgent.toLowerCase()
};
(function(b){
b.IsIE=b.s.Contains(msie);
b.IsIE5=b.s.Contains(msie5);
b.IsIE6=b.s.Contains(msie6);
b.IsIE7=b.s.Contains(msie7);
b.IsIE56=!b.IsIE7&&(b.IsIE6b.IsIE5);
b.IsGecko=b.s.Contains(gecko);
b.IsSafari=b.s.Contains(safari);
b.IsOpera=b.s.Contains(opera);
b.IsMac=b.s.Contains(macintosh);

b.IsIELike=(b.IsIEb.IsOpera);
b.IsGeckoLike=(b.IsGeckob.IsSafari);
})(Browser);
functionoAjax(){
this.req=null;
this.url=;
this.content=;
this.type=text;
this.encode=;
this.asyn=true;
this.action=get;
this.error=false;
}
oAjax.prototype.init=function(){
if(window.XMLHttpRequest){
this.req=newXMLHttpRequest();
}
elseif(window.ActiveXObject){
//isIE=true;
try{
this.req=newActiveXObject(Msxml2.XMLHTTP);
}
catch(e){
try{
this.req=newActiveXObject(Microsoft.XMLHTTP);
}
catch(e){
this.req=false;
}
}
}
varself=this;
if(this.req){
this.req.onreadystatechange=function(){self.listener()};
}
};

oAjax.prototype.listener=function(){
if(this.req.readyState==4){
if(this.req.status==200){
//right
try{
this.callback(Browser.IsIE&&this.encode==gb2312?oAjax.gb2utf8(this.req.responseBody):(this.type==text?this.req.responseText:this.req.responseXML));
}
catch(e){
}
}
else{
//error
this.halt([callbackerror]+this.req.status);
}
}
};

oAjax.prototype.send=function(url){
this.init();

url=this.url=urlthis.url;
this.content=!!this.content?this.content:;
this.encode=this.encode?this.encode.toLowerCase():;
this.asyn=this.asyn==undefined?true:!!this.asyn;
this.action=(this.action==undefinedthis.action==get)?Get:Post;
this.error=this.error==undefined?false:!!this.error;

if(!url&&this.error){
alert(Ajax请求URL不能为空。);
return;
}
try{
this.req.open(this.action,url,this.asyn);
}
catch(e){
this.halt([open]+e.name+:+e.message);
return;
}
try{
this.req.setRequestHeader(Connection,close);
this.req.setRequestHeader(Accept-Encoding,gzip,deflate);
this.req.setRequestHeader(Content-Type,application/x-
if(this.req.overrideMimeType&&this.encode){
this.req.overrideMimeType(text/xml+(this.encode?;charset=+this.encode:));
}
this.req.send(this.content);
}
catch(e){
this.halt([open]+e.name+:+e.message+\n**检查是否为跨域访问。);
}
};

oAjax.prototype.callback=function(content){
//alert(content);
};

//abort
oAjax.prototype.abort=function(){
this.req.abort();
};

oAjax.prototype.halt=function(description){
this.error&&alert(description);
};

//gb2312toutf8
oAjax.gb2utf8=function(data){
varglbEncode=[];
gb2utf8_data=data;
execScript(gb2utf8_data=MidB(gb2utf8_data,1),VBScript);
vart=escape(gb2utf8_data).replace(/%u/g,).replace(/(.{2})(.{2})/g,%$2%$1).replace(/%([A-Z].)%(.{2})/g,@$1$2);
t=t.split(@);
vari=0,j=t.length,k;
while(++i<j){
k=t[i].substring(0,4);
if(!glbEncode[k]){
gb2utf8_char=eval(0x+k);
execScript(gb2utf8_char=Chr(gb2utf8_char),VBScript);
glbEncode[k]=escape(gb2utf8_char).substring(1,6);
}
t[i]=glbEncode[k]+t[i].substring(4);
}
gb2utf8_data=gb2utf8_char=null;
returnunescape(t.join(%));
}
*/

核心代码
复制代码 代码如下:
varb=xmlhttp.responseText;
varobj=eval((+b+));
document.getElementById(fedcount).innerHTML=obj.b;
document.getElementById(feedcounttop).innerHTML=obj.b;


评论


亲,登录后才可以留言!