Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# $.getJSON中无法识别的url_C#_Jquery_Asp.net_Json_Web Services - Fatal编程技术网

C# $.getJSON中无法识别的url

C# $.getJSON中无法识别的url,c#,jquery,asp.net,json,web-services,C#,Jquery,Asp.net,Json,Web Services,我在使用$时遇到问题。getJSON,因为我总是遇到错误“请求格式无法识别以'/GetBranchs'意外结尾的URL” 这是我的密码: $.getJSON('testWS.asmx/GetBranches', function (data, status, xhr) { console.log(data); }); 以下是web服务的代码 [WebMethod] [ScriptMethod(UseHttp

我在使用
$时遇到问题。getJSON
,因为我总是遇到错误“
请求格式无法识别以'/GetBranchs'意外结尾的URL

这是我的密码:

$.getJSON('testWS.asmx/GetBranches', function (data, status, xhr) {
                        console.log(data);
                    });
以下是
web服务的代码

[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public List<BranchesModel> GetBranches()
{
    return BranchesBLL.Instance.GetBranches();
}
[WebMethod]
[ScriptMethod(UseHttpGet=true,ResponseFormat=ResponseFormat.Json)]
公共列表getBranchs()
{
返回BranchesBLL.Instance.getBranchs();
}

我的URL有什么问题?如何解决此问题,以便使用$.getJSON函数?

您的web配置中似乎缺少以下几行。。 因为默认情况下,ASP.NET 2.0及更高版本禁用GET&POST

因此,请将这些行添加到web.config并尝试

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


尝试使用小写数据类型:“json”一个是
GET
另一个是
POST