//不带参数
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("POST",url,false);//POST or GET , url , true or false
xmlhttp.send();
如果第三个参数改为true:
xmlhttp.onreadystatechange = function(){
if( xmlhttp.readyState==4 )){
//do
}
};
//带一个xml发送到后台
页面body添加一个xml
<xml id="CallBackFlowInfo">
<Msg>
<SEQ_ID/>
<FLOW_ID/>
<CALL_BACK/>
<EXPECT_SCORE/>
<CONFIRM_SCORE/>
</Msg>
</xml>
给xml节点赋值:
CallBackFlowInfo.XMLDocument.selectSingleNode("/Msg/EXPECT_SCORE").text=str;
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("POST",url,false);//POST or GET , url , true or false
xmlhttp.send(CallBackFlowInfo.XMLDocument);
java后台读取:
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
request.setCharacterEncoding("UTF-8");
response.setContentType("text/xml; charset=GBK");
PrintWriter out = response.getWriter();
StringBuffer xmlReturn = new StringBuffer(XML.XML_HEAD);
HttpSession session = request.getSession();
StaffInfo info = (StaffInfo) session.getAttribute("staffInfo");
Document doc = null;
SAXReader saxReader = new SAXReader();
Element root = doc.getRootElement();
String FLOW_ID=root.elementText("FLOW_ID");
得到返回结果:
字符串:xmlhttp.responseText
xml文档:
var drpXML = new ActiveXObject("Microsoft.XMLDOM");
drpXML.load(xmlhttp.responseXML);
var drpRows = drpXML.selectNodes("/root/rowSet");
for(r=0;r<drpRows.length;r++){
drpRows[r].selectSingleNode("TABLE_NAME_MAIN").text;//获得返回结果的值
}