Ajax from chinaz get comments code _ javascript skills

Source: Internet
Author: User
Chinaz uses ajax to read comments. The following is a reference to the chinaz code. The characters obtained by ajax are similar to the following content:

The Code is as follows:


{:"

Supported: [0] Objection: [0] Chinese webmaster site netizen: Anonymous on comment:

Who thinks that Google AdSense websites cannot be promoted? Dumb

", B: 1}


Then use the following ajax for output.

The Code is as follows:



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 ();
// Whether an error is displayed
// Ajax. error = true;
// The requested page is encoded as 'gb2312' or empty.
// Ajax. encode = 'gb2312 ';
// Callback function
Ajax. callback = function (content ){
// Process the returned content
Eval ('var obj = '+ content );
Document. getElementById ('bk BK '). innerHTML = obj.;
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 ('bk BK '). innerHTML = obj.;
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 ('bk BK '). innerHTML = obj.;
// 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 + "& 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 ){}
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 request URL cannot be blank. ');
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 ** check whether CORS is enabled. ');
}
};

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 ("% "));
}
*/


Core code

The Code is as follows:


Var B = xmlhttp. responseText;
Var obj = eval ("(" + B + ")");
Document. getElementById ('bk BK '). innerHTML = obj.;
Document. getElementById ('fedcount'). innerHTML = obj. B;
Document. getElementById ('feedcounttop '). innerHTML = obj. B;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.