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

时间:2016-04-27 08:18:58

标签: javascript php ajax xml

我必须将Xml发送到其他服务器(旅游公司的Web服务)并在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>

响应必须看起来像

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

请帮助我!

1 个答案:

答案 0 :(得分:1)

它应该与此接近(使用jQuery):

//This component will be used to page between the various fragments created.
List<Fragment> fragments = new ArrayList<>();
fragments.add(new MyFragment());
final ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), fragments);