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