如何使用Jquery和Ajax在XML中发送请求和接收响应

时间:2018-07-25 08:45:33

标签: php jquery ajax xml soap

我有一个名为AmaSend.xml的xml文件。因此,我必须将此XML文件作为请求发送,并且我想从另一个XML文件获得响应。然后我尝试如下。但是,我总是得到

  

ReferenceError:未定义xml

如何解决此问题并发送请求和接收响应?

这是AmaAll.php文件

<html>
<body>

<script type="text/javascript">

$(document).ready(function () {

                        var sourceOffice = 'Value1';
                        var originator = 'Value2';
                        var referenceIdentifier = 'Value3';
                        var organizationId = 'Value4';
                        var binaryData = 'Value5';

                        var originatorTypeCode = 'Value6';
                        var referenceQualifier = 'Value7';
                        var dataLength = '8';
                        var dataType = 'E';

                        console.log(sourceOffice);

                        var query = '<?xml version="1.0"?><Security_Authenticate><userIdentifier><originIdentification><sourceOffice>Value1</sourceOffice>/originIdentification><originatorTypeCode>U</originatorTypeCode><originator>Value2</originator></userIdentifier>'+
            '<dutyCode><dutyCodeDetails><referenceQualifier>DUT</referenceQualifier><referenceIdentifier>SU</referenceIdentifier></dutyCodeDetails></dutyCode>'+
             '<systemDetails><organizationDetails><organizationId>NMC-I</organizationId></organizationDetails></systemDetails>'+
             '<passwordInfo><dataLength>8</dataLength><dataType>E</dataType><binaryData>Value3</binaryData></passwordInfo></Security_Authenticate>';

                        $.ajax({
                        url: 'AmaRes.xml',
                        data: query, 
                        type: 'POST',
                        contentType: "text/xml",
                        dataType: "xml",
                        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("statusCode")[0].attr("id"));
                        },
                    });             

                    });

    </script>

</body>
</html>

这是AmaSend.xml文件(Request)。

<?xml version="1.0"?>
<Security_Authenticate>
  <userIdentifier>
    <originIdentification>
      <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>Value7</dataLength>
    <dataType>Value8</dataType>
    <binaryData>Value9</binaryData>
  </passwordInfo>
 </Security_Authenticate>

这是AmaRes.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>Value2</awss:SequenceNumber>
      <awss:SecurityToken>Value3</awss:SecurityToken>
    </awss:Session>
  </soap:Header>
  <soap:Body>
    <Security_AuthenticateReply xmlns="http://xml.amadeus.com/VLSSLR_06_1_1A">
      <processStatus>
        <statusCode>Value4</statusCode>
      </processStatus>
    </Security_AuthenticateReply>
  </soap:Body>
</soap:Envelope>

0 个答案:

没有答案