如何使用Jquery,Ajax发送SOAP标头并从服务器获取响应

时间:2018-08-02 04:48:09

标签: javascript jquery ajax soap

我正在创建一个网页。在此网页中,我想显示通过Web服务获取的详细信息。但是,要做的是在此之前,我必须发送头并从服务器获取访问令牌。然后,我实现了这样的代码。现在,Web浏览器的控制台没有显示任何错误。 但是,当我尝试警告响应代码时,显示为未定义。

我想要显示或提醒Response sessionId。我该怎么办??

$(document).ready(function() {
  $.ajax({
    type: 'POST',
    url: 'AmaRes.xml',
    contentType: 'text/xml; charset=utf-8',
    headers: {
      SOAPAction: 'WSDL_File.wsdl'
    },
    data: '<?xml version="1.0"?><Security_Authenticate><userIdentifier><sourceOffice>Value1</sourceOffice></originIdentification><originatorTypeCode>Value2</originatorTypeCode><originator>Value3</originator></userIdentifier><dutyCode><dutyCodeDetails><referenceQualifier>Value4</referenceQualifier><referenceIdentifier>Value5</referenceIdentifier></dutyCodeDetails></dutyCode><systemDetails><organizationDetails><organizationId>Value6</organizationId></organizationDetails></systemDetails><passwordInfo><dataLength>8</dataLength><dataType>E</dataType><binaryData>Value7</binaryData></passwordInfo></Security_Authenticate>',
    success: function(xmlResponse) {
      var xmlhttp = new window.XMLHttpRequest();

      xmlResponse = $.parseXML(xmlResponse),
        $xml = $(xmlResponse),
        $title = $xml.find("statusCode"); //to get the ResponseId for example
      alert(($xml).find("wss:Session").attr("awss:SessionId"));
    },
  });

});

AmaRes.xml是响应xml文件。

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:awss="http://xml.amadeus.com/ws/2009/01/WBS_Session-2.0.xsd">
  <soap:Header>
    <awss:Session>
      <awss:SessionId>Value1</awss:SessionId>
      <awss:SequenceNumber>1</awss:SequenceNumber>
      <awss:SecurityToken>Value2</awss:SecurityToken>
    </awss:Session>
  </soap:Header>
  <soap:Body>
    <Security_AuthenticateReply xmlns="http://xml.amadeus.com/VLSSLR_06_1_1A">
      <processStatus>
        <statusCode>Value3</statusCode>
      </processStatus>
    </Security_AuthenticateReply>
  </soap:Body>
</soap:Envelope>

1 个答案:

答案 0 :(得分:0)