Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Processing a soap response with javascript.. In IE

Posted on 2006-06-30
5
Medium Priority
?
236 Views
Last Modified: 2012-05-05
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</hintResult>
    </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.XMLHTTP");
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader("Content-Type","application/soap+xml; charset=utf-8")
xmlHttp.send(strEnvelope);
xmlHttp.onreadystatechange = checkState;
}
}
function checkState(){
  if(xmlHttp.readyState=="complete"||xmlHttp.readyState==4){
   placeHint(xmlHttp.responseXML);
     }
  else{
  alert("Not Complete");
  }
}
 function placeHint(xmlresponse) {
 alert(xmlresponse);
 response  = xmlresponse.documentElement;
  method = response.getElementsByTagName('hint')[0].firstChild.data;
  result = response.getElementsByTagName('Term')[0].firstChild.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
0
Comment
Question by:werD420
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 

Author Comment

by:werD420
ID: 17020713
I changed to this but still have the same problems
 method = response.getElementsByTagName('hintResponse')[0].firstChild.data;
  result = response.getElementsByTagName('hintResult')[0].firstChild.data;
0
 

Author Comment

by:werD420
ID: 17021956
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.XMLHTTP");
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8")
xmlHttp.send(strEnvelope);
xmlHttp.onreadystatechange = checkState;
}
}
function checkState(){
  if(xmlHttp.readyState=="complete"||xmlHttp.readyState==4){
   placeHint(xmlHttp.responseXML);
   
     }
  else{
  alert("Not Complete");
  }
}
 function placeHint(xmlresponse) {
 var response;
 alert(xmlHttp.responseXML);
 oDoc =new ActiveXObject("MSXML2.DOMDocument.4.0")  
 oDoc.async = true;
 oDoc.setProperty("SelectionNamespaces","xmlns:soap='http://www.w3.org/2001/XMLSchema'")
 oDoc.load(xmlresponse)
 alert(oDoc.readyState);
 if(oDoc.readyState == 4 || oDoc.readyState == "complete"){
  result = oDoc.getElementsByTagName('hintResult')
 
  alert(result);
  }  else
  {
  alert("Not Ready")
}
}
</script>
0
 

Author Comment

by:werD420
ID: 17024384
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.DOMDocument.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("SelectionNamespaces",sNamespaces);
 var sXPath="/*/soap:Body/default:hintResponse/default:hintResult";
 resultNode = oDoc.selectSingleNode(sXPath);
 alert(resultNode.text);
}
0
 

Author Comment

by:werD420
ID: 17025846
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.XMLHTTP");
xmlHttp.open('POST', url , true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
var sendText=document.getElementById("Term").value
xmlHttp.send("Term="+sendText);
xmlHttp.onreadystatechange = checkState;
 }
 //checking for readiness
function checkState(){
  if(xmlHttp.readyState=="complete"||xmlHttp.readyState==4){
   placeHint2(xmlHttp.responseXML);
   }
}
//adding data to page through transform
function placeHint2(xmlresponse){
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load(xmlresponse)
// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("hint.xsl")
// Transform
document.getElementById("suggested").innerHTML =  xml.transformNode(xsl);
}
</script>
0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 17162178
werD420,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question