problem with calling remote ASMX using jQuery

前端 未结 4 1881
一向
一向 2021-01-21 10:52

Been trying my best to understand this correctly. What is the difference between an XML, SOAP and JSON response? And how does one know how to call a web service whose response i

4条回答
  •  甜味超标
    2021-01-21 11:47

    I have used this web service before. It expects and returns XML. Here's the code I used to get to work in Internet Explorer (For Firefox you need to use the jsonp).

    $('#Currency').bind('change', function() {
        var targetDiv = '#Result'
        var currencyValue = $('#Currency option:selected').val();
        var webMethod = 'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate';
        var parameters = "?FromCurrency=GBP&ToCurrency=" + currencyValue;
    
        $(targetDiv).html('loading...');
    
        $.ajax({
            type: "GET",
            url: webMethod + parameters ,
            contentType: "text/xml; charset=utf-8", 
            dataType: "xml", //for Firefox change this to "jsonp"
            success: function(response) {
                $(targetDiv).html(response.text);
            },
            error: function(xhr, textStatus, errorThrown) {
                $(targetDiv).html("Unavailable: " + textStatus);
            }
        });
    )};
    

提交回复
热议问题