我在 asp.net 中开发了一个 Web 服务,并且能够从项目内的 aspx 页面对其进行测试,并且可以轻松显示以 JSON 格式返回的信息。
我现在需要从独立的 html 页面使用 Web 服务。
有人有这方面的经验吗?我对将取代这个的部分感到困惑
<asp:ScriptManager ID="ScriptManager" runat="server">
<Services>
<asp:ServiceReference Path="~\MyService.asmx" />
</Services>
</asp:ScriptManager>
如果直接使用 html 和 javascript 无法做到这一点,有人可以向我展示一个可以做到这一点的独立 php 页面吗?
最佳答案
请参阅此链接:
http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/
使用 JQuery
www.jquery.org
本质上,您使 Web 服务脚本可调用,只是 Web 服务定义中的一个属性,您可以:
$.ajax({
type: "POST",
url: "~/MyService.asmx/MyMethod",
data: "{parameterName:'" aStringArgument + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
var data = msg.d
// Now var is an object with properties just like your object
}
});
关于asp.net - 使用从独立 html 页面返回 json 的 asp.net Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/383680/