使用从独立 html 页面返回 json 的 asp.net web 服务

mso*_*son 2 asp.net json web-services

我已经在 asp.net 中开发了一个 Web 服务,并且能够从项目内的 aspx 页面对其进行测试,并且可以轻松显示以 JSON 格式返回的信息。

我现在需要从独立的 html 页面使用 Web 服务。

有人有这方面的经验吗?我对取代它的部分感到困惑

<asp:ScriptManager ID="ScriptManager" runat="server">
    <Services>
        <asp:ServiceReference Path="~\MyService.asmx" />
    </Services>
</asp:ScriptManager>
Run Code Online (Sandbox Code Playgroud)

如果直接使用 html 和 javascript 无法做到这一点,有人可以向我展示一个可以做到这一点的独立 php 页面吗?

Bob*_*toe 5

请参阅此链接:

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
    }
  });
Run Code Online (Sandbox Code Playgroud)