ajax

来源:互联网 发布:js 自定义对象方法 编辑:程序博客网 时间:2024/06/11 10:40
function createXMLHttp(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}

}


//异步加载数据
function ajaxForData(process,vatno,content){
if(xmlHttp == null){
createXMLHttp();
}
var url = "MtgSPC?action=loadData";
var queryString = "process=" + process + "&vatno=" + vatno + "&content=" + content;
xmlHttp.open("POST",url,false);
xmlHttp.onreadystatechange = afterLoadCallback;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(queryString);
}


function afterLoadCallback(){
if(xmlHttp.readyState==4){
if(xmlHttp.responseText){
var node = xmlHttp.responseXML.documentElement;
var pkey = node.getElementsByTagName("pkey");
//var content = node.getElementsByTagName("content");
var controlRange = node.getElementsByTagName("controlRange");
var standard = node.getElementsByTagName("standard");
var analyze = node.getElementsByTagName("analyze");
var countCoefficient = node.getElementsByTagName("countCoefficient");
var addMedicationCoefficient = node.getElementsByTagName("addMedicationCoefficient");
var addMedication = node.getElementsByTagName("addMedication");
var addMedicationUnit = node.getElementsByTagName("addMedicationUnit");
var noControlForm = node.getElementsByTagName("noControlForm");
var noControlTo = node.getElementsByTagName("noControlTo");
var ifcase = node.getElementsByTagName("ifcase");
var remark = node.getElementsByTagName("remark");
var controlP = node.getElementsByTagName("controlP");

if(pkey[0].firstChild != null && pkey[0].firstChild.nodeValue != ""){
document.editspcitem.pkey.innerText = pkey[0].firstChild.nodeValue; 
}


if(controlRange[0].firstChild != null && controlRange[0].firstChild.nodeValue != "" && 
  controlRange[0].firstChild.nodeValue != 'null'){
document.editspcitem.controlRange.innerText = controlRange[0].firstChild.nodeValue;
}else{
document.editspcitem.controlRange.innerText = '';
}

if(standard[0].firstChild != null && standard[0].firstChild.nodeValue != "" && 
  standard[0].firstChild.nodeValue != 'null'){
document.editspcitem.standard.innerText = standard[0].firstChild.nodeValue;
}else{
document.editspcitem.standard.innerText = '';
}

if(analyze[0].firstChild != null && analyze[0].firstChild.nodeValue != "" && 
  analyze[0].firstChild.nodeValue != 'null'){
document.editspcitem.analyze.innerText = analyze[0].firstChild.nodeValue;
}else{
document.editspcitem.analyze.innerText = '';
}

if(countCoefficient[0].firstChild != null && countCoefficient[0].firstChild.nodeValue != "0.00000"){
document.editspcitem.countCoefficient.innerText = countCoefficient[0].firstChild.nodeValue;
}else{
document.editspcitem.countCoefficient.innerText = "0.00000";
}

if(addMedicationCoefficient[0].firstChild != null && addMedicationCoefficient[0].firstChild.nodeValue != "0.00000"){
document.editspcitem.addMedicationCoefficient.innerText = addMedicationCoefficient[0].firstChild.nodeValue;
}else{
document.editspcitem.addMedicationCoefficient.innerText = '';
}

if(addMedication[0].firstChild != null && addMedication[0].firstChild.nodeValue != "" && 
  addMedication[0].firstChild.nodeValue != 'null'){
document.editspcitem.addMedication.innerText = addMedication[0].firstChild.nodeValue;
}else{
document.editspcitem.addMedication.innerText = '';
}

if(addMedicationUnit[0].firstChild != null && addMedicationUnit[0].firstChild.nodeValue != "" && 
  addMedicationUnit[0].firstChild.nodeValue != 'null'){
document.editspcitem.addMedicationUnit.innerText = addMedicationUnit[0].firstChild.nodeValue;
}else{
document.editspcitem.addMedicationUnit.innerText = '';
}

if(noControlForm[0].firstChild != null && noControlForm[0].firstChild.nodeValue != "" &&
  noControlTo[0].firstChild != null && noControlTo[0].firstChild.nodeValue != ""){
document.editspcitem.noControlForm.innerText = noControlForm[0].firstChild.nodeValue;
document.editspcitem.noControlTo.innerText = noControlTo[0].firstChild.nodeValue;
}else{
document.editspcitem.noControlForm.innerText = '';
document.editspcitem.noControlTo.innerText = '';
}

if(ifcase[0].firstChild != null && ifcase[0].firstChild.nodeValue != ""){
document.getElementById("ifcase").checked = ifcase[0].firstChild.nodeValue=="true"?true:false;
}

if(remark[0].firstChild != null && remark[0].firstChild.nodeValue != "" && 
  remark[0].firstChild.nodeValue != "null"){
document.editspcitem.remark.innerText = remark[0].firstChild.nodeValue;
}else{
document.editspcitem.remark.innerText = '';
}

if(controlP[0].firstChild != null && controlP[0].firstChild.nodeValue != ""){
document.editspcitem.controlP.innerText = controlP[0].firstChild.nodeValue;
}else{
document.editspcitem.controlP.innerText = '0';
}

document.getElementById("statusMessages").innerText = '';
//hideLoadingPage();
setTimeout("hideLoadingPage();",1000);
}

}
}




function editSave(){
var parameters;
var con;
parameters = setParameters();
con = confirm("确实要更新吗?");
if(con == true){
if(xmlHttp == null){
createXMLHttp();
}

showLoadingPage();

var url = "MtgSPC?action=saveSPCItem";
var queryString = "parameters=" + parameters + '&mode=edit';
xmlHttp.open("POST",url,false);
xmlHttp.onreadystatechange = afterUpdateCallback;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(queryString);
}

}

原创粉丝点击