Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何访问SOAP响应属性?_Javascript_Jquery_Soap_Enyo - Fatal编程技术网

Javascript 如何访问SOAP响应属性?

Javascript 如何访问SOAP响应属性?,javascript,jquery,soap,enyo,Javascript,Jquery,Soap,Enyo,全部 从最近几天开始,我发现如何使用JS访问soap,毕竟我从这个链接中得到了解决方案 现在我可以让我的soap请求处于警报状态。 但是我想使用它的属性并打印响应(我指的是解析响应和显示) 这是我的密码 const xmlhttp = new XMLHttpRequest(); xmlhttp.open('POST', 'http://service.project-development-site.de/soap.php', true); xmlhttp.onreadystatechange

全部

从最近几天开始,我发现如何使用JS访问soap,毕竟我从这个链接中得到了解决方案

现在我可以让我的soap请求处于警报状态。 但是我想使用它的属性并打印响应(我指的是解析响应和显示)

这是我的密码

const xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://service.project-development-site.de/soap.php', true);
xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState == 4) {
    alert(xmlhttp.responseText);

    // http://www.terracoder.com convert XML to JSON
    let json = XMLObjectifier.xmlToJSON(xmlhttp.responseXML);
    const result = json.Body[0].GetQuoteResponse[0].GetQuoteResult[0].Text;
    // Result text is escaped XML string, convert string to XML object then convert to JSON object
    json = XMLObjectifier.xmlToJSON(XMLObjectifier.textToXML(result));
    alert(symbol + ' Stock Quote: $' + json.Stock[0].Last[0].Text);
  }
};
xmlhttp.setRequestHeader('SOAPAction', 'http://service.project-development-site.de/soap.php');
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
const xml =
  '<?xml version="1.0" encoding="utf-8"?>' +
  '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">' +
  '<soapenv:Header/>' +
  '<soapenv:Body>' +
  '<tem:loginUserSoapInPart>' +
  '<tem:userName>user</tem:userName>' +
  '<tem:passWord>pwd</tem:passWord>' +
  '<tem:accesToken>acktoken</tem:accesToken>' +
  '</tem:loginUserSoapInPart>' +
  '</soapenv:Body>' +
  '</soapenv:Envelope>';
xmlhttp.send(xml);
constxmlhttp=newxmlhttprequest();
xmlhttp.open('POST','http://service.project-development-site.de/soap.php",对),;
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4){
警报(xmlhttp.responseText);
// http://www.terracoder.com 将XML转换为JSON
让json=XMLObjectifier.xmlToJSON(xmlhttp.responseXML);
const result=json.Body[0]。GetQuoteResponse[0]。GetQuoteResult[0]。文本;
//结果文本是转义的XML字符串,将字符串转换为XML对象,然后转换为JSON对象
json=XMLObjectifier.xmlToJSON(XMLObjectifier.textToXML(结果));
警报(symbol+'Stock Quote:$'+json.Stock[0]。最后一个[0]。文本);
}
};
setRequestHeader('SOAPAction','http://service.project-development-site.de/soap.php');
setRequestHeader('Content-Type','text/xml');
常量xml=
'' +
'' +
'' +
'' +
'' +
“用户”+
“pwd”+
“acktoken”+
'' +
'' +
'';
send(xml);
我得到了这样的反应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
   <SOAP-ENV:Body>
      <ns1:loginUserSoapOutPart>
         <ns1:error>
            <ns1:errorCode>0</ns1:errorCode>
            <ns1:errorShortDesc>OK</ns1:errorShortDesc>
            <ns1:errorLongDesc>SOAP request executed successfully .</ns1:errorLongDesc>
         </ns1:error>
         <ns1:soapOut>
            <ns1:accesToken>accesToken</ns1:accesToken>
            <ns1:ACK>ACK</ns1:ACK>
         </ns1:soapOut>
      </ns1:loginUserSoapOutPart>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

0
好啊
SOAP请求已成功执行。
阿克斯托肯
阿克
我想显示这个响应属性,比如errorShortDesc,errorLongDesc等等。。。 我该怎么办

提前感谢

试着用这种方式

var xmlResponse =xmlhttp.responseXML.documentElement;

var fullNodeList = xmlResponse.getElementsByTagName("loginUserSoapOutPart");

for (var i=0; i < fullNodeList.length; i++)
{
  var eachnode = new Option();
  eachnode.text = fullNodeList[i].childNodes[0].nodeValue;
  eachnode.value = fullNodeList[i].attributes[0].value;
}
var xmlResponse=xmlhttp.responseXML.documentElement;
var fullNodeList=xmlResponse.getElementsByTagName(“loginUserSoapOutPart”);
对于(变量i=0;i
jQuery自1.5版以来添加了一个
parseXML
实用程序,用于将字符串解析为XML,然后相应地访问节点

在您的示例中,您可以按如下方式使用它,
response
是服务器的响应:

  var xmlDoc = $.parseXML( response ),
      $xml = $( xmlDoc ),
      $value= $xml.find( "errorShortDesc" );
      //do what you want with the value
  console.log($value.text());