Ajax original request and how to skip J2EE framework

原生ajax request:
//===================Ajax Frame Start======================================
var xmlRequest=null;
//Send Ajax Request
function ajaxRequest(url){
	xmlRequest = null;
	if(window.ActiveXObject){
		xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlRequest = new XMLHttpRequest();
	}
	//'GET',URL asynchronous
  	xmlRequest.open("GET", url, true);
  	xmlRequest.onreadystatechange=invoke; 
  	xmlRequest.send(null);
}
//Callback Method For Ajax Request
function invoke(){
	if(xmlRequest != null && xmlRequest.readyState == 4) {
		if (xmlRequest.status == 200) {
			parse(xmlRequest);
		} else {
			alert("Ajax call failed!");
		}
	}
}
//Parse XML For Ajax Request
function parse(xmlRequest){
	var xmlDoc = xmlRequest.responseXML;
	var message = xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue;
	var errors = xmlDoc.getElementsByTagName("Error");
	if(errors.length!=0){
		for(var i=0;i<errors.length;i++){
			message = message+"\n"+errors[i].childNodes[0].nodeValue;
		}
	}
	alert(message);
} 
//===================Ajax Frame End======================================


Example: html call BW, skip J2EE framework.
<!DOCTYPE HTML>
<head><script>
calculate=function(){

	var a  = document.getElementById("007").value;
	var b  = document.getElementById("009").value;
	var c  = document.getElementById("sel_op").value;
	var Host = "";
	var Post = ""
	if(verify(a)&&verify(b)){

		try {
		
			var posturl = encodeURI("http://10.114.206.147:40252/myself/intfProcess_Definition-service.serviceagent/portTypeEndpoint1");
			var requestXml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:sch=\"http://www.tibco.com/schemas/test/myself/Schema.xsd\">" + 
				"<soapenv:Header/>" + 
				"<soapenv:Body>" + 
					"<sch:root>" + 
						"<sch:valueA>" + Number(a) + "</sch:valueA>" + 
						"<sch:valueB>" + Number(b) + "</sch:valueB>" + 
						"<sch:po>" + c + "</sch:po>" + 
					"</sch:root>" + 
				"</soapenv:Body>" + 
			"</soapenv:Envelope>";
		 
			var xmlHttpReq = false;
			var self = this;
			if (window.XMLHttpRequest) {
				self.xmlHttpReq = new XMLHttpRequest();
			}else if (window.ActiveXObject) {
				self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			self.xmlHttpReq.open('POST', posturl, true);
			self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			self.xmlHttpReq.setRequestHeader('SOAPAction', '/myself/intfProcess_Definition-service.serviceagent/portTypeEndpoint1/Process_sp_DefinitionOp');
			self.xmlHttpReq.onreadystatechange = function() {
				console.log(self.xmlHttpReq.readyState);
				if (self.xmlHttpReq.readyState == 4) {
					console.log(self.xmlHttpReq.status);
					if (self.xmlHttpReq.status == 200) {
						var strResponse= self.xmlHttpReq.responseText;
						console.log('strResponse='+strResponse);
						parse(self.xmlHttpReq);
					}
				}
			}
			self.xmlHttpReq.send(requestXml);
		} catch (e) {
			alert(e);
		}
	}else{
		alert("Pls enter a valid number!");
	}
}

function parse(xmlRequest){
	var xmlDoc = xmlRequest.responseXML;
	var result = xmlDoc.getElementsByTagName("ns0:result")[0].childNodes[0].nodeValue;
	document.getElementById("010").value= result;
} 

var verify = function(value){
	if(value==''||value==undefined){
		return  false;
	}
	return true;
}


</script>
</head>
<body>
	<div style="padding: 30px; border:1px solid blue; width:300px;">
	<table>
		<tr>
			<th colspan='5' align="left">Calculation: A+B=?</th>
		</tr>
		<tr>
			<td><input style="width:75px;" onkeyup="this.value=this.value.replace(/\D/g,'')" id='007' type='text' ></td>
			<td>
				<select id="sel_op">
					<option value="+">+</option>
					<option value="-">-</option>
					<option value="*">*</option>
					<option value="/">/</option>
				</select>
			</td>
			<td><input style="width:75px;" onkeyup="this.value=this.value.replace(/\D/g,'')" id='009'  type='text'  ></td>
			<td>=</td>
			<td><input style="width:75px;" id='010' type='text'></td>
		</tr>
		<tr>
			<TD></TD>
			<TD></TD>
			<td><input id='011' type='button' value='calculate' onclick='calculate()' style="background-color:cyan;" ></td>
			<TD></TD>
			<TD></TD>
		</tr>
	</table>
	<div>
</body>

 

你可能感兴趣的:(Ajax original request and how to skip J2EE framework)