topical media & game development
basic-xml-15-listing25all.htm / htm
<html>
<head>
<title>GET Tester</title>
<script language="JavaScript">
function updateTotal(){
var qty = orderForm.qty.value;
var unitPrice = orderForm.unitPrice.value;
xdDoc = new ActiveXObject("MSXML.DOMDocument");
xhHTTP = new ActiveXObject("MSXML2.XMLHTTP");
xhHTTP.open("GET", "http://localhost/soap/updateTotal2.asp?quantity="
+ qty + "&unitPrice=" + unitPrice, false);
xhHTTP.send();
xdDoc = xhHTTP.responseXML;
alert(xdDoc.xml);
var discount, extPrice;
discount = xdDoc.selectSingleNode("//o:discount").text + "% off";
extPrice = xdDoc.selectSingleNode("//o:extPrice").text;
document.getElementById("discount").innerHTML = discount;
orderForm.extPrice.value = extPrice;
}
function sendOrder(){
var xdDoc, xhHTTP, sXML
sXML = "<env:Envelope xmlns:env="
sXML = sXML + "'http://www.w3.org/2003/05/soap-envelope'>"
sXML = sXML + "<env:Body>"
sXML = sXML + "<o:addToCart "+
"xmlns:o='http://www.sernaferna.com/soap/ordersystem'>";
sXML = sXML + " <o:cartId>"+orderForm.cartId.value+"</o:cartId>";
sXML = sXML + " <o:item itemId='"+orderForm.itemId.value+"'>";
sXML = sXML + " <o:quantity>"+orderForm.qty.value+"</o:quantity>";
sXML = sXML + " <o:extPrice>"+orderForm.extPrice.value+"</o:extPrice>";
sXML = sXML + " </o:item>";
sXML = sXML + "</o:addToCart>";
sXML = sXML + "</env:Body>";
sXML = sXML + "</env:Envelope>";
xdDoc = new ActiveXObject("MSXML.DOMDocument");
xdDoc.loadXML(sXML);
xhHTTP = new ActiveXObject("MSXML2.XMLHTTP");
xhHTTP.open("POST", "http://localhost/soap/submitOrder1.asp", false);
xhHTTP.send(xdDoc);
xdDoc = xhHTTP.responseXML;
var responseName;
responseName = xdDoc.selectSingleNode("//env:Body").firstChild.nodeName;
if (responseName == "env:Fault") {
var reason, message
reason =
xdDoc.selectSingleNode("//env:Reason/env:Text").firstChild.nodeValue;
message = xdDoc.selectSingleNode("//o:message").firstChild.nodeValue;
alert(reason+":\n"+message);
} else {
var orderNumber, status, total;
cartId = xdDoc.selectSingleNode("//o:cartId").firstChild.nodeValue;
status = xdDoc.selectSingleNode("//o:status").firstChild.nodeValue;
itemId = xdDoc.selectSingleNode("//o:itemId").firstChild.nodeValue;
submitDiv.innerHTML = "<b>Item "+itemId+" added to cart #"+cartId+"</b>";
}
}
</script>
</head>
<body>
<h1>SOAP Pricing Tool</h1>
<form name="orderForm" id="orderForm">
<input type="hidden" name="itemId" id="itemId" value="ZIBKA" />
<input type="hidden" name="cartId" id="cartId" value="THX1138" />
Quantity: <input id="qty" name="qty" size="3" onChange="updateTotal();"
value="0" />
<br />
Item: <i>Zibka Smiles</i>, by The Polka Dot Zither Band
<br />
Discount: <span id="discount"></span>
<br />
Unit Price: <input id="unitPrice" name="unitPrice" value="12.95" size="4"/>
<br />
Extended Price: <input id="extPrice" name="extPrice" size="4" value="0" />
<div id="submitDiv">
<input type="button" value="Add to cart" id="submitButton" name="submitButton"
onclick="sendOrder()">
</div>
</form>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.