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);
//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 = DocumentHelper.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 departName = node.addElement("departName");
departName.setText(item.getDepartName());
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;
===========================
利用函數格式化 POST 請求參數
function addParam(paramObj, paramName, paramValue){
if(paramObj.length > 0)
paramObj += "&";
return paramObj + encodeURIComponent(paramName)
+ "=" + encodeURIComponent(paramValue);
}
=============================================
javascript 裡面的遍曆
for (pop in windowxxxx){
.....
}