有没有办法从JavaScript中调用Web服务?我知道你可以添加一个脚本管理器来拉取Web服务,但我不知道如何在完成后从JavaScript访问这些功能。
谢谢, 马特
谢谢, 马特
本主题介绍了如何使用ECMAScript(JavaScript)调用Web服务。为了使应用程序能够通过客户端脚本调用ASP.NET AJAX Web服务,服务器异步通信层会自动生成JavaScript代理类。对于每个Web服务,在页面中的
<asp:ScriptManager>
控件下包含<asp:ServiceReference>
元素,则将生成一个代理类。
请查看Dave Ward撰写的使用jQuery消费ASP.NET JSON Web服务。
$(document).ready(function() {
$.ajax({
type: "POST",
url: "RSSReader.asmx/GetRSSReader",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Hide the fake progress indicator graphic.
$('#RSSContent').removeClass('loading');
// Insert the returned HTML into the <div>.
$('#RSSContent').html(msg.d);
}
});
});