使用Jquery使用WCF服务不起作用

时间:2013-11-19 23:23:52

标签: ajax wcf jquery

我有一个hello world WCF,如下所示: 我添加了:aspNetCompatibilityEnabled =“true”

public string GetData()
{
    return "Hello world";
}

<system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
 </system.webServer>

我有一个非常简单的HTML页面:

<body>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                type: "GET",
                url: "http://localhost:49311/Service1.svc/GetData/",
                dataType: "xml",
                success: function () {
                    alert("test ok");
                },
                error: function (e) {
                    alert("error: " +e.responseText);
                }
            });
        });
      </script>
</body>

我不断收到提醒说:“错误:”

不确定我是否遗漏了什么......?

非常感谢!

0 个答案:

没有答案