About handwritten Ajax

Source: Internet
Author: User

Function createhttprequest (){
VaR httprequest = false;
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 createxml (STR ){
If (document. All ){
VaR xmldom = new activexobject ("Microsoft. xmldom ")
Xmldom. loadxml (STR)
Return xmldom
}
Else
Return new domparser (). parsefromstring (STR, "text/XML ")
}

 

 

Function showschedule (SID, f ){
VaR url = "../schedule. do? Operate = tofindbyid ";
VaR poststr = "uid =" + encodeuri (SID );

// Questions about frequent data transmission initialization in IE
Httprequest. Open ("Post", URL, true );
Httprequest. onreadystatechange = function (){
If (httprequest. readystate = 4)
If (httprequest. Status = 200 ){
VaR xml = createxml (httprequest. responsetext );
VaR item = xml. getelementsbytagname ("Schedule") [0];

VaR scheduleid = item. getelementsbytagname ("scheduleid") [0]. firstchild. nodevalue;
VaR Title = item. getelementsbytagname ("title") [0]. firstchild. nodevalue;
VaR schcontent = item. getelementsbytagname ("schcontent") [0]. firstchild. nodevalue;
VaR address = item. getelementsbytagname ("Address") [0]. firstchild. nodevalue;
VaR ifprivate = item. getelementsbytagname ("ifprivate") [0]. firstchild. nodevalue;
VaR createtime = item. getelementsbytagname ("createtime") [0]. firstchild. nodevalue;
VaR begintime = item. getelementsbytagname ("begintime") [0]. firstchild. nodevalue;
VaR endtime = item. getelementsbytagname ("endtime") [0]. firstchild. nodevalue;
VaR meetingid = item. getelementsbytagname ("meetingid") [0]. firstchild. nodevalue;

F. scheduleid. value = scheduleid;
F. Title. value = title;
F. Address. value = address;
F. meetingid. value = meetingid;
F. schcontent. value = schcontent;
If (ifprivate = 0)
F. ifprivate. Checked = true;
Else
F. ifprivate. Checked = false;

F. begintime. value = begintime;
F. endtime. value = endtime;
F. Option. value = "domodify ";
}
}
Httprequest. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
Httprequest. Send (poststr );
}

==========================================

Dom4j-1.6.1.jar

Import org. dom4j. Document;
Import org. dom4j. documenthelper;
Import org. dom4j. element;

Document Doc = incluenthelper. createdocument ();
Element Node = Doc. addelement ("depart ");

Element departid = node. addelement ("departid ");
Departid. settext (item. getdepartid (). tostring ());
Element branchid = node. addelement ("branchid ");
Branchid. settext (item. getbranchid (). tostring ());
Element Extension name = node. addelement ("extension name ");
Registrant name. settext (item. getpipeline name ());
Element principaluserid = node. addelement ("principaluserid ");
Principaluserid. settext (item. getprincipaluserid (). tostring ());
Element connecttelno = node. addelement ("connecttelno ");
Connecttelno. settext (item. getconnecttelno ());
Element connectmobiletelno = node. addelement ("connectmobiletelno ");
Connectmobiletelno. settext (item. getconnectmobiletelno ());
Element faxes = node. addelement ("faxes ");
Faxes. settext (item. getfaxes ());

Printwriter out = response. getwriter ();
Out. println (Doc. asxml ());
Out. Flush ();
Out. Close ();

======================================

Request. setcontenttype ("text/XML ");

Httprequest. resoponsexml;

======================================
Format POST Request Parameters Using Functions

Function addparam (paramobj, paramname, paramvalue ){
If (paramobj. length> 0)
Paramobj + = "&";
Return paramobj + encodeuricomponent (paramname)
+ "=" + Encodeuricomponent (paramvalue );
}

========================================================== =====
Traversal in Javascript

For (pop in windowxxxx ){
.....
}

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.