使用jQuery调用远程ASMX的问题 [英] problem with calling remote ASMX using jQuery

查看:75
本文介绍了使用jQuery调用远程ASMX的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽我所能正确理解这一点. XML,SOAP和JSON响应之间有什么区别?以及如何知道如何调用响应是以上之一的Web服务? (...如果我偏离轨道,请纠正我)

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 is one of the above? (...Please correct me if I'm off-track)

我之所以问这个原因是因为我试图在我的.NET3.5 Webapp中从jQuery调用远程ASMX,根本没有运气!基本上,我正在尝试调用此地址所示的CurrencyConverter方法: http://www .webservicex.net/CurrencyConvertor.asmx?op = ConversionRate

The reason I ask this because I am trying to call a remote ASMX from jQuery within my .NET3.5 webapp, and no luck at all!! Basically I am trying to call a CurrencyConverter method as shown at this address: http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate

我可以看到它返回XML,但是以下代码不起作用:

I can see that it returns XML, but the following code does not work:

$('#Currency').bind('change', function() {
    var targetDiv = '#Result'
    var currencyValue = $('#Currency option:selected').attr('value')
    var webMethod = 'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate'
    var parameters = "{'FromCurrency':'GBP','ToCurrency':'" + currencyValue + "'}"

    $(targetDiv).html('loading...');

    $.ajax({
        type: "POST",
        url: webMethod,
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            $(targetDiv).html(response.d);
        },
        error: function(response) {
            $(targetDiv).html("Unavailable:" + response);
        }
    });
});

请帮助我,因为我真的迷路了!

Please could someone assist me with this, as I am really lost!

谢谢!

推荐答案

我以前曾经使用过此Web服务.它期望并返回XML.这是我用来在Internet Explorer中工作的代码(对于Firefox,您需要使用jsonp).

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);
        }
    });
)};

这篇关于使用jQuery调用远程ASMX的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆