關於手寫 Ajax

來源:互聯網
上載者: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);
       
    //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){
    .....
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.