简体   繁体   English

使用 Ajax 或 Javascript 发送 XML 请求并从其他服务器接收 XML 响应

[英]Send XML Request and receive XML Response from other server using Ajax or Javascript

I have to send an Xml to other server(an web service of a travel company) and receive response in Xml An example of xml request is: .......................................................................................................................................................我必须向其他服务器(旅游公司的 Web 服务)发送一个 Xml 并以 Xml 接收响应 一个 xml 请求示例是:....... ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ……………………………………………………………………………………………………………………………………………………………………………………………………

<?xml version="1.0" encoding="UTF-8"?>
    <Request RequestType="getCountryRequest">
        <AuditInfo>
            <RequestId>
                001
            </RequestId>
            <RequestUser>
                user
            </RequestUser>
            <RequestPass>
                password
            </RequestPass>
            <RequestTime>
                2012-09-04T18:00:46
            </RequestTime>
            <RequestLang>
                RO
            </RequestLang>
        </AuditInfo>
        <RequestDetails>
            <getCityRequest CountryCode="RO"/>  
        </RequestDetails>
    </Request>

And the response must look like并且响应必须看起来像

<?xml version="1.0" encoding="utf-8"?> 
<Response ResponseType="getCityResponse">   
    <AuditInfo>     
        <ResponseId>
            12940524
        </ResponseId>     
        <RequestId>
            12949986
        </RequestId>     
        <ResponseTime>
            2012-09-04T18:10:02
        </ResponseTime>   
    </AuditInfo>   
    <ResponseDetails>     
        <getCityResponse>       
            <City>         
                <CountryCode>
                    ENG
                </CountryCode>         
                <CityCode>
                    ENG
                </CityCode>         
                <CityName>
                    Madrid
                </CityName> 
            </City>
        </getCityResponse>   
    </ResponseDetails> 
</Response>

Please help me!请帮我!

It should be something close to this (using jQuery):它应该与此接近(使用 jQuery):

    var query = '<?xml version="1.0" encoding="UTF-8"?><Request RequestType="getCountryRequest"><AuditInfo><RequestId>001</RequestId>'+
            '<RequestUser>user</RequestUser><RequestPass>password</RequestPass><RequestTime>2012-09-04T18:00:46</RequestTime><RequestLang>'+
             'RO</RequestLang></AuditInfo><RequestDetails><getCityRequest CountryCode="RO"/></RequestDetails></Request>';

    $.ajax({
    url: 'YOUR_URL_HERE',
    data: query, 
    type: 'POST',
    contentType: "text/xml",
    dataType: "text",
    success : function (xmlResponse){
        xmlResponse = $.parseXML( xmlResponse ),
        $xml = $( xmlResponse ),
        $title = $xml.find( "ResponseId" ); //to get the ResponseId for example
    },
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用jQuery从Cross-Domain Ajax请求接收XML响应 - Receive XML response from Cross-Domain Ajax request with jQuery 使用AJAX从服务器发送和接收信息 - Using AJAX to send and receive info from a server 解析来自API,Javascript,Ajax的XML响应 - Parse XML response from API, Javascript, Ajax 如何从服务器向其他客户端发送请求并接收客户端的响应,然后在 node.js 中发送数据? - How can I send request from server to other clients and receive response from clients and then send data in node.js? JavaScript-AJAX:从服务器访问XML文件 - JavaScript - AJAX : Accessing an XML File from a Server 我如何使用Ajax向php xml_rpc服务器发送请求 - How can i send a request to php xml_rpc server using ajax 如何在 JavaScript 中发送 XML 请求 - How to send XML request in JavaScript 如何在PRE标签中显示来自AJAX请求的XML响应 - how to display XML response from AJAX request in a PRE tag 如何在 Cypress 中使用 JavaScript 在 GET API 的请求正文中发送 XML。 以 JSON 格式发送请求会给出响应,因为输入格式不正确 - How to send XML in request body of a GET API using JavaScript in Cypress. Sending request in JSON format gives response as Input was not well formed 如何发送ajax请求以请求XML响应到asp.net MVC 4控制器? - How to send ajax request to request XML response to asp.net MVC 4 controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM