Javascript 从jQuery Ajax调用WCF service POST方法
我有以下WCF方法Javascript 从jQuery Ajax调用WCF service POST方法,javascript,c#,jquery,ajax,wcf,Javascript,C#,Jquery,Ajax,Wcf,我有以下WCF方法 [OperationContract] [WebInvoke(Method = "POST")] public string HelloWorld(string stest) { return stest.ToString(); } 我有一个jQuery Ajax客户端代码,如下所示 $.ajax({ type: "POST", contentType: "application/json; charset=utf-8",
[OperationContract]
[WebInvoke(Method = "POST")]
public string HelloWorld(string stest)
{
return stest.ToString();
}
我有一个jQuery Ajax客户端代码,如下所示
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '../../Service.svc/HelloWorld',
data: { 'stest': 'testdata' },
dataType: 'json',
success: function (resp) {
},
error: function (error)
{
alert(error);
}
});
当ajax调用HellowWorld方法时,获取
网络错误:500内部服务器错误
如何从jquery ajax调用wcf Post方法。设置一个断点并检查其是否命中服务器代码。。。并安装fiddler来检查这个ajax调用发送了什么。以下是安装fiddler的路径。请将此添加到web.config
并将此属性添加到服务类[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Required)]
请更新您在fiddler请求中获得的内容。此问题已解决。现在,当我在services中将jsonstring作为参数传递时,我遇到了另一个错误,所以将解决方案作为答案发布并接受它。。。并安装fiddler来检查这个ajax调用发送了什么。以下是安装fiddler的路径。请将此添加到web.config
并将此属性添加到服务类[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Required)]
请更新您在fiddler请求中获得的内容。此问题已解决。现在,当我在services中将jsonstring作为参数传递时,我遇到了另一个错误,所以将解决方案作为答案发布并接受它。