werD420
asked on
Processing a soap response with javascript.. In IE
Hello all im trying to consume a web service using javascript and soap but i cant seem to figure out how to getthe response,
Any help with this is greatly appreciated im at a loss on it
Here's what the soap response looks like
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<hintResponse xmlns="http://microsoft.com/webservices/">
<hintResult>string</hintRe sult>
</hintResponse>
</soap12:Body>
</soap12:Envelope>
Here's the Code
<script type="text/javascript" language=javascript>
var xmlHttp;
var strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"+
" <soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
" xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" +
" <soap12:Body>" +
" <hint xmlns='http://microsoft.com/webservices'>" +
" <Term>b</Term></hint>" +
" </soap12:Body>" +
"</soap12:Envelope>";
function showHint(str)
{
if (str.length > 0)
{
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLH TTP");
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader(" Content-Ty pe","appli cation/soa p+xml; charset=utf-8")
xmlHttp.send(strEnvelope);
xmlHttp.onreadystatechange = checkState;
}
}
function checkState(){
if(xmlHttp.readyState=="co mplete"||x mlHttp.rea dyState==4 ){
placeHint(xmlHttp.response XML);
}
else{
alert("Not Complete");
}
}
function placeHint(xmlresponse) {
alert(xmlresponse);
response = xmlresponse.documentElemen t;
method = response.getElementsByTagN ame('hint' )[0].first Child.data ;
result = response.getElementsByTagN ame('Term' )[0].first Child.data ;
}
</script>
I receive [object] in the alert inside of the placeHint function but then receive the error that response is null or not an object. Im not even sure if this is the best method for getting the data. Like i said id appreciate any insight
Any help with this is greatly appreciated im at a loss on it
Here's what the soap response looks like
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<hintResponse xmlns="http://microsoft.com/webservices/">
<hintResult>string</hintRe
</hintResponse>
</soap12:Body>
</soap12:Envelope>
Here's the Code
<script type="text/javascript" language=javascript>
var xmlHttp;
var strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"+
" <soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
" xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" +
" <soap12:Body>" +
" <hint xmlns='http://microsoft.com/webservices'>" +
" <Term>b</Term></hint>" +
" </soap12:Body>" +
"</soap12:Envelope>";
function showHint(str)
{
if (str.length > 0)
{
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLH
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader("
xmlHttp.send(strEnvelope);
xmlHttp.onreadystatechange
}
}
function checkState(){
if(xmlHttp.readyState=="co
placeHint(xmlHttp.response
}
else{
alert("Not Complete");
}
}
function placeHint(xmlresponse) {
alert(xmlresponse);
response = xmlresponse.documentElemen
method = response.getElementsByTagN
result = response.getElementsByTagN
}
</script>
I receive [object] in the alert inside of the placeHint function but then receive the error that response is null or not an object. Im not even sure if this is the best method for getting the data. Like i said id appreciate any insight
ASKER
Here's the latest version im trying to load the response into another object then iterate through it but im getting nowhere i get two alerts that say object and one that says 4 . both appear to create and load but i cant figure out how to access the elements
<script type="text/javascript" language=javascript>
var xmlHttp;
var strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"+
" <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
" xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>" +
" <soap:Body>" +
" <hint xmlns='http://microsoft.com/webservices'>" +
" <Term>b</Term></hint>" +
" </soap:Body>" +
"</soap:Envelope>";
function showHint(str)
{
if (str.length > 0)
{
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLH TTP");
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader(" Content-Ty pe","text/ xml; charset=utf-8")
xmlHttp.send(strEnvelope);
xmlHttp.onreadystatechange = checkState;
}
}
function checkState(){
if(xmlHttp.readyState=="co mplete"||x mlHttp.rea dyState==4 ){
placeHint(xmlHttp.response XML);
}
else{
alert("Not Complete");
}
}
function placeHint(xmlresponse) {
var response;
alert(xmlHttp.responseXML) ;
oDoc =new ActiveXObject("MSXML2.DOMD ocument.4. 0")
oDoc.async = true;
oDoc.setProperty("Selectio nNamespace s","xmlns: soap='http://www.w3.org/2001/XMLSchema'")
oDoc.load(xmlresponse)
alert(oDoc.readyState);
if(oDoc.readyState == 4 || oDoc.readyState == "complete"){
result = oDoc.getElementsByTagName( 'hintResul t')
alert(result);
} else
{
alert("Not Ready")
}
}
</script>
<script type="text/javascript" language=javascript>
var xmlHttp;
var strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"+
" <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
" xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>" +
" <soap:Body>" +
" <hint xmlns='http://microsoft.com/webservices'>" +
" <Term>b</Term></hint>" +
" </soap:Body>" +
"</soap:Envelope>";
function showHint(str)
{
if (str.length > 0)
{
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLH
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader("
xmlHttp.send(strEnvelope);
xmlHttp.onreadystatechange
}
}
function checkState(){
if(xmlHttp.readyState=="co
placeHint(xmlHttp.response
}
else{
alert("Not Complete");
}
}
function placeHint(xmlresponse) {
var response;
alert(xmlHttp.responseXML)
oDoc =new ActiveXObject("MSXML2.DOMD
oDoc.async = true;
oDoc.setProperty("Selectio
oDoc.load(xmlresponse)
alert(oDoc.readyState);
if(oDoc.readyState == 4 || oDoc.readyState == "complete"){
result = oDoc.getElementsByTagName(
alert(result);
} else
{
alert("Not Ready")
}
}
</script>
ASKER
Ive updated my placeHint function but i get object required are the alert line any thoughts?
function placeHint(xmlresponse) {
var resultNode;
oDoc =new ActiveXObject("MSXML2.DOMD ocument.4. 0")
oDoc.async = false;
oDoc.load(xmlresponse)
var sNamespaces = "xmlns:soap='http://www.w3.org/2001/XMLSchema'" + " xmlns:default='http://microsoft.com/webservices/'";
oDoc.setProperty("Selectio nNamespace s",sNamesp aces);
var sXPath="/*/soap:Body/defau lt:hintRes ponse/defa ult:hintRe sult";
resultNode = oDoc.selectSingleNode(sXPa th);
alert(resultNode.text);
}
function placeHint(xmlresponse) {
var resultNode;
oDoc =new ActiveXObject("MSXML2.DOMD
oDoc.async = false;
oDoc.load(xmlresponse)
var sNamespaces = "xmlns:soap='http://www.w3.org/2001/XMLSchema'" + " xmlns:default='http://microsoft.com/webservices/'";
oDoc.setProperty("Selectio
var sXPath="/*/soap:Body/defau
resultNode = oDoc.selectSingleNode(sXPa
alert(resultNode.text);
}
ASKER
well... I finished it on my own screw the soap i used a post and screw traversing xml with javascript this is an easy and good way to it using xslt
<script language=javascript type="text/javascript">
//posting data to webservice
function postdata(){
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLH TTP");
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader(" Content-Ty pe","appli cation/x-w ww-form-ur lencoded") ;
var sendText=document.getEleme ntById("Te rm").value
xmlHttp.send("Term="+sendT ext);
xmlHttp.onreadystatechange = checkState;
}
//checking for readiness
function checkState(){
if(xmlHttp.readyState=="co mplete"||x mlHttp.rea dyState==4 ){
placeHint2(xmlHttp.respons eXML);
}
}
//adding data to page through transform
function placeHint2(xmlresponse){
// Load XML
var xml = new ActiveXObject("Microsoft.X MLDOM")
xml.async = false
xml.load(xmlresponse)
// Load XSL
var xsl = new ActiveXObject("Microsoft.X MLDOM")
xsl.async = false
xsl.load("hint.xsl")
// Transform
document.getElementById("s uggested") .innerHTML = xml.transformNode(xsl);
}
</script>
<script language=javascript type="text/javascript">
//posting data to webservice
function postdata(){
var url="http://localhost:3601/WebSite2/hint.asmx/hint";
xmlHttp=new ActiveXObject("Msxml2.XMLH
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader("
var sendText=document.getEleme
xmlHttp.send("Term="+sendT
xmlHttp.onreadystatechange
}
//checking for readiness
function checkState(){
if(xmlHttp.readyState=="co
placeHint2(xmlHttp.respons
}
}
//adding data to page through transform
function placeHint2(xmlresponse){
// Load XML
var xml = new ActiveXObject("Microsoft.X
xml.async = false
xml.load(xmlresponse)
// Load XSL
var xsl = new ActiveXObject("Microsoft.X
xsl.async = false
xsl.load("hint.xsl")
// Transform
document.getElementById("s
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
method = response.getElementsByTagN
result = response.getElementsByTagN