我一直在尽力正确理解这一点。 XML、SOAP 和 JSON 响应之间有什么区别?人们如何知道如何调用其响应为上述之一的 Web 服务? (……如果我偏离了轨道,请纠正我)
我问这个问题的原因是因为我试图在我的.NET3.5 web应用程序中从jQuery调用远程ASMX,但完全没有运气!基本上我试图调用一个CurrencyConverter方法,如以下地址所示:http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate
我可以看到它返回 XML,但以下代码不起作用:
$('#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);
}
});
});
请有人帮助我,因为我真的迷路了!
谢谢你!
我以前使用过这个网络服务。它期望并返回 XML。这是我用来在 Internet Explorer 中工作的代码(对于 Firefox,您需要使用 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);
}
});
)};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)