DeDe-Ajax-js Application

Source: Internet
Author: User

Introduction: This is a detailed page for DeDe-Ajax-js applications. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 339595 'rolling = 'no'>

<! --
// XMLHTTP and xmldom objects
VaR dedexhttp = NULL;
VaR dedexdom = NULL;
VaR dedecontainer = NULL;
VaR dedeshowerror = false;
VaR dedeshowwait = false;
VaR deerrcon = "";
VaR dedeerrdisplay = "failed to download data ";
VaR dedewaitdisplay = "downloading data ...";

// Obtain the element of the specified ID

Function $ de (ID ){
Return document. getelementbyid (ID );
}

// Gcontainer is the container that saves the downloaded content.
// Whether mshowerror prompts an error message
// Dedeshowwait indicates whether to wait for the message.
// What string is returned by the merrcon server is considered as an error
// Information displayed when an error occurs in merrdisplay
// Message displayed when mwaitdisplay is waiting
// Call deajax by default ('divid', false, false ,'','','')

Function dedeajax (gcontainer, mshowerror, mshowwait, merrcon, merrdisplay, mwaitdisplay)
{
Dedecontainer = gcontainer;
Dedeshowerror = mshowerror;
Dedeshowwait = mshowwait;
If (merrcon! = "") Dedeerrcon = merrcon;
If (merrdisplay! = "") Dedeerrdisplay = merrdisplay;
If (merrdisplay = "X") dedeerrdisplay = "";
If (mwaitdisplay! = "") Dedewaitdisplay = mwaitdisplay;

// Key-value pairs for sending data via post or get
This. Keys = array ();
This. Values = array ();
This. keycount =-1;
This. sendlang = 'gb2312 ';

// Request Header type
This. Rtype = 'text ';

// Initialize XMLHTTP
// IE6 and ie5
If (window. activexobject ){
Try {dedexhttp = new activexobject ("msxml2.xmlhttp");} catch (e ){}
If (dedexhttp = NULL) Try {dedexhttp = new activexobject ("Microsoft. XMLHTTP");} catch (e ){}
}
Else {
Dedexhttp = new XMLHttpRequest ();
}

// Add a post or get key-Value Pair
This. addkeyn = function (skey, svalue ){
If (this. sendlang = 'utf-8') This. addkeyutf8 (skey, svalue );
Else this. addkey (skey, svalue );
};

This. addkey = function (skey, svalue ){
This. keycount ++;
This. Keys [This. keycount] = skey;
Svalue = svalue + '';
If (svalue! = '') Svalue = svalue. Replace (/\ +/g, '$ # $ ');
This. Values [This. keycount] = escape (svalue );
};

// Add a post or get key-Value Pair
This. addkeyutf8 = function (skey, svalue ){
This. keycount ++;
This. Keys [This. keycount] = skey;
Svalue = svalue + '';
If (svalue! = '') Svalue = svalue. Replace (/\ +/g, '$ # $ ');
This. Values [This. keycount] = encodeuri (svalue );
};

// Add an HTTP request header key-Value Pair
This. addhead = function (skey, svalue ){
This. rkeycount ++;
This. rkeys [This. rkeycount] = skey;
This. rvalues [This. rkeycount] = svalue;
};

// Clear the hash table parameters of the current object
This. clearset = function (){
This. keycount =-1;
This. Keys = array ();
This. Values = array ();
This. rkeycount =-1;
This. rkeys = array ();
This. rvalues = array ();
};

Dedexhttp. onreadystatechange = function (){
// This event will be executed in IE6 regardless of blocking or asynchronous mode.
If (dedexhttp. readystate = 4 ){
If (dedexhttp. Status = 200)
{
If (dedexhttp. responsetext! = Dedeerrcon ){
Dedecontainer. innerhtml = dedexhttp. responsetext;
}
Else {
If (dedeshowerror) dedecontainer. innerhtml = dedeerrdisplay;
}
Dedexhttp = NULL;
}
Else {If (dedeshowerror) dedecontainer. innerhtml = dedeerrdisplay ;}
}
Else {If (dedeshowwait) dedecontainer. innerhtml = dedewaitdisplay ;}
};

// Check the status of the blocking mode
This. barragestat = function (){
If (dedexhttp = NULL) return;
If (typeof (dedexhttp. Status )! = Undefined & amp; dedexhttp. Status = 200)
{
If (dedexhttp. responsetext! = Dedeerrcon ){
Dedecontainer. innerhtml = dedexhttp. responsetext;
}
Else {
If (dedeshowerror) dedecontainer. innerhtml = dedeerrdisplay;
}
}
};

// Send the HTTP Request Header
This. sendhead = function ()
{
// Send the User-Defined Request Header
If (this. rkeycount! =-1)
{
For (VAR I = 0; I <= This. rkeycount; I ++)
{
Dedexhttp. setRequestHeader (this. rkeys [I], this. rvalues [I]);
}
}
If (this. Rtype = 'binary '){
Dedexhttp. setRequestHeader ("Content-Type", "multipart/form-Data ");
} Else {
Dedexhttp. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
}
};

// Send data in post Mode
This. sendpost = function (purl ){
VaR pdata = "";
VaR I = 0;
This. State = 0;
Dedexhttp. Open ("Post", purl, true );
This. sendhead ();
// Post Data
If (this. keycount! =-1)
{
For (; I <= This. keycount; I ++)
{
If (pdata = "") pdata = This. Keys [I] + '=' + this. Values [I];
Else pdata + = "&" + this. Keys [I] + '=' + this. Values [I];
}
}
Dedexhttp. Send (pdata );
};

// Send data in get Mode
This. sendget = function (purl ){
VaR gkey = "";
VaR I = 0;
This. State = 0;
// Get Parameters
If (this. keycount! =-1)
{
For (; I <= This. keycount; I ++)
{
If (gkey = "") gkey = This. Keys [I] + '=' + this. Values [I];
Else gkey + = "&" + this. Keys [I] + '=' + this. Values [I];
}
If (Purl. indexof ('? ') =-1) purl = purl + '? '+ Gkey;
Else purl = purl + '&' + gkey;
}
Dedexhttp. Open ("get", purl, true );
This. sendhead ();
Dedexhttp. Send (null );
};

// use get to send data. Blocking Mode
This. sendget2 = function (purl) {
var gkey = "";
var I = 0;
This. state = 0;
// get parameter
If (this. keycount! =-1)
{< br> for (; I <= This. keycount; I ++)
{< br> If (gkey = "") gkey = This. keys [I] + '=' + this. values [I];
else gkey + = "&" + this. keys [I] + '=' + this. values [I];
}< br> If (Purl. indexof ('? ') =-1) purl = purl + '? '+ Gkey;
else purl = purl +' & '+ gkey;
}< br> dedexhttp. open ("get", purl, false);
This. sendhead ();
dedexhttp. send (null);
// Firefox directly checks the xhttp status
This. barragestat ();
};

// Send data in post Mode
This. sendpost2 = function (purl ){
VaR pdata = "";
VaR I = 0;
This. State = 0;
Dedexhttp. Open ("Post", purl, false );
This. sendhead ();
// Post Data
If (this. keycount! =-1)
{
For (; I <= This. keycount; I ++)
{
If (pdata = "") pdata = This. Keys [I] + '=' + this. Values [I];
Else pdata + = "&" + this. Keys [I] + '=' + this. Values [I];
}
}
Dedexhttp. Send (pdata );
// Directly checks the xhttp status in Firefox
This. barragestat ();
};

} // End class dedeajax

// Initialize xmldom
Function initxdom (){
If (dedexdom! = NULL) return;
VaR OBJ = NULL;
// Gecko, Mozilla, and Firefox
If (typeof (domparser )! = "Undefined "){
VaR parser = new domparser ();
OBJ = parser. parsefromstring (xmltext, "text/XML ");
}
// IE
Else {
Try {OBJ = new activexobject ("msxml2.domdocument");} catch (e ){}
If (OBJ = NULL) Try {OBJ = new activexobject ("Microsoft. xmldom");} catch (e ){}
}
Dedexdom = OBJ;
};

// Read and write cookie Functions
Function getcookie (c_name)
{
If (document. Cookie. length> 0)
{
C_start = Document. Cookie. indexof (c_name + "= ")
If (c_start! =-1)
{
C_start = c_start + c_name.length + 1;
C_end = Document. Cookie. indexof (";", c_start );
If (c_end =-1)
{
C_end = Document. Cookie. length;
}
Return Unescape (document. Cookie. substring (c_start, c_end ));
}
}
Return null
}

Function setcookie (c_name, value, expiredays)
{
VaR exdate = new date ();
Exdate. setdate (exdate. getdate () + expiredays );
Document. Cookie = c_name + "=" + escape (value) + (expiredays = NULL )? "": "; Expires =" + exdate. togmtstring (); // make the set effective time correct. Add togmtstring ()
}

// Ajax call
Function Ajax (ID, URL)
{
VaR taget_obj = Document. getelementbyid (ID );
Myajax = new dedeajax (taget_obj, false, false ,'','','');
Myajax. sendget2 (URL );
Dedexhttp = NULL;
}

-->

<Div id = "ajax1"> <a href = "javascript: Ajax ('ajax1', 'xx. php')"> Ajax test </a> </div>

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/339595.html pageno: 8.

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.