最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

來自chinaz的ajax獲取評論代碼_javascript技巧

來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 20:39:11
文檔

來自chinaz的ajax獲取評論代碼_javascript技巧

來自chinaz的ajax獲取評論代碼_javascript技巧:ajax獲取到的字符是類似下面的內(nèi)容 代碼如下:{a:支持:[ 0 ] 反對:[ 0 ]中國站長站網(wǎng)友:匿名 于 2008-04-25 評論道:誰認(rèn)為投放了Google AdSense的站點(diǎn)就不允許進(jìn)行推廣了?傻子吧,b:1}然后用下面的ajax進(jìn)行輸出 代碼如下:var key='';
推薦度:
導(dǎo)讀來自chinaz的ajax獲取評論代碼_javascript技巧:ajax獲取到的字符是類似下面的內(nèi)容 代碼如下:{a:支持:[ 0 ] 反對:[ 0 ]中國站長站網(wǎng)友:匿名 于 2008-04-25 評論道:誰認(rèn)為投放了Google AdSense的站點(diǎn)就不允許進(jìn)行推廣了?傻子吧,b:1}然后用下面的ajax進(jìn)行輸出 代碼如下:var key='';

ajax獲取到的字符是類似下面的內(nèi)容
代碼如下:
{a:"支持:[ 0 ] 反對:[ 0 ]中國站長站網(wǎng)友:匿名 于 2008-04-25 評論道:誰認(rèn)為投放了Google AdSense的站點(diǎn)就不允許進(jìn)行推廣了?傻子吧",b:1}

然后用下面的ajax進(jìn)行輸出
代碼如下:

var key='';
var str=new Array();

function createAjaxObj(){
var httprequest=false
//document.domain='chinaz.com';
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml');
}
else if (window.ActiveXObject){ // if IE
try
{
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest;
}

function load_feedback(arcID,pg){

/*
var url = "http://www.chinaz.com/plus/feedback_ajax.php?action=show&arcID="+arcID+"&pg="+pg;
var ajax = new oAjax();
// 是否顯示錯誤
//ajax.error = true;
// 請求的頁面的編碼為'gb2312'或空
//ajax.encode = 'gb2312';
// 回調(diào)函數(shù)
ajax.callback = function (content) {
// 處理返回內(nèi)容
eval('var obj = ' + content);
document.getElementById('fedbk').innerHTML=obj.a;
document.getElementById('fedcount').innerHTML=obj.b;
};
ajax.send(url);
*/

var xmlhttp = createAjaxObj();
try
{

var params="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){}
function f()
{

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


function load_allfeedback(arcID,pg){

var xmlhttp = createAjaxObj();
try
{

var params="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){}
function f()
{

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

function feed_back(){

var msg = trim(document.getElementById('msg').value);
var arcID = document.getElementById('arcID').value;
var username = trim(document.getElementById('username').value);
var pwd = trim(document.getElementById('pwd').value);
var checkbox = document.getElementById('notuser');
if(checkbox.checked)
var notuser = 1;
else
var notuser = 0;


var xmlhttp = createAjaxObj();
try
{

params="action=send&arcID="+arcID+"&msg="+msg+"&username="+username
+"&pwd="+pwd+"¬user="+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){}
function f()
{
if(xmlhttp.readyState!= 4 || xmlhttp.status!=200 )
return ;
var arr = 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);
}
}

}

function goodbad(fid,arcid,actname,pg){


var xmlhttp = 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){}
function f()
{
if(xmlhttp.readyState!= 4 || xmlhttp.status!=200 )
return ;
var arr = xmlhttp.responseText.split("@:");

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

}

function goodbad2(fid,arcid,actname,pg){


var xmlhttp = 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){}
function f()
{
if(xmlhttp.readyState!= 4 || xmlhttp.status!=200 )
return ;
var arr = xmlhttp.responseText.split("@:");

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

}

function pg(vl){
var arcID = document.getElementById('arcID').value;
load_feedback(arcID,vl);
}
function pg2(arcID,vl){
//var arcID = document.getElementById('arcID').value;
load_allfeedback(arcID,vl);
}
function ck_yzimg(){
//document.all.cknum.value='';
document.all.msg.value='';
document.all.username.value='';
document.all.pwd.value='';
document.getElementsByName('sb')[0].disabled = false;
//document.all.img1.onclick();
}

function trim(s) {
return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );

}

//////
/*
String.prototype.Contains = function(str) {
return (this.indexOf(str) > -1);
};
var Browser = {
s : navigator.userAgent.toLowerCase()
};
(function (b) {
b.IsIE = b.s.Contains('msie');
b.IsIE5 = b.s.Contains('msie 5');
b.IsIE6 = b.s.Contains('msie 6');
b.IsIE7 = b.s.Contains('msie 7');
b.IsIE56 = !b.IsIE7 && (b.IsIE6 || b.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.IsIE || b.IsOpera);
b.IsGeckoLike = (b.IsGecko || b.IsSafari);
}) (Browser);
function oAjax () {
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 = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
// isIE = true;
try {
this.req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
this.req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
this.req = false;
}
}
}
var self = 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) {
this.halt('[callback] ' + e.name + ':' + e.message);
}
}
else {
// error
this.halt('[callback error] ' + this.req.status);
}
}
};

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

url = this.url = url || this.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 == undefined || this.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-www-form-urlencoded' + (this.encode ? ';charset=' + this.encode : ''));
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);
};

// gb2312 to utf8
oAjax.gb2utf8 = function (data) {
var glbEncode = [];
gb2utf8_data = data;
execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
var t = escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
t = t.split("@");
var i=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;
return unescape(t.join("%"));
}
*/

核心代碼
代碼如下:
var b= xmlhttp.responseText;
var obj = eval("("+b+")");
document.getElementById('fedbk').innerHTML=obj.a;
document.getElementById('fedcount').innerHTML=obj.b;
document.getElementById('feedcounttop').innerHTML=obj.b;

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

來自chinaz的ajax獲取評論代碼_javascript技巧

來自chinaz的ajax獲取評論代碼_javascript技巧:ajax獲取到的字符是類似下面的內(nèi)容 代碼如下:{a:支持:[ 0 ] 反對:[ 0 ]中國站長站網(wǎng)友:匿名 于 2008-04-25 評論道:誰認(rèn)為投放了Google AdSense的站點(diǎn)就不允許進(jìn)行推廣了?傻子吧,b:1}然后用下面的ajax進(jìn)行輸出 代碼如下:var key='';
推薦度:
標(biāo)簽: 評論的 代碼 代碼代碼
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top