【问题标题】:Unrecognized url in $.getJSON [duplicate]$.getJSON 中无法识别的 url [重复]
【发布时间】:2014-02-25 06:46:03
【问题描述】:

我在使用$.getJSON 时遇到问题,因为我总是收到错误“Request format is unrecognized for URL unexpectedly ending in '/GetBranches'

这是我的代码:

$.getJSON('testWS.asmx/GetBranches', function (data, status, xhr) {
                        console.log(data);
                    });

这是web service的代码

[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public List<BranchesModel> GetBranches()
{
    return BranchesBLL.Instance.GetBranches();
}

我的网址有什么问题?我怎样才能解决这个问题,以便我可以使用 $.getJSON 函数?

【问题讨论】:

  • 尝试使用小案例 dataType: 'json'
  • 一个是GET另一个是POST

标签: c# jquery asp.net json web-services


【解决方案1】:

您的网络配置中似乎缺少以下几行。 因为 ASP.NET 2.0 及更高版本默认禁用 GET 和 POST

所以将这些行添加到您的 web.config 并尝试...

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

更多信息.. http://aspadvice.com/blogs/ssmith/archive/2007/09/04/FIX-Request-format-is-unrecognized-for-URL-unexpectedly-ending-in.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多