简体   繁体   中英

How To Send SOAP Header With Jquery, Ajax And Get Response From The Server

I am creating a web page. In this web page , I want to show details which is get by web service. But , the thing is before do this , I have to send headers and get the access tokens from the server. Then I have implemented a code like this. now console of the web browser doesn't show me any kind of error. But , when I tries to alert response code it shows me undefined.

What I want is I want to show or alert Response sessionId. How can I do it ??

$(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 is the response xml file.

<?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>

您是否尝试过Header Interface https://developer.mozilla.org/en-US/docs/Web/API/Headers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM