【发布时间】:2011-11-14 02:54:43
【问题描述】:
不幸的是,它只在调用 .ajax() 时遇到错误条件,而 textStatus(第二个参数)只说“错误”。我已经阅读了有关 stackoverflow 的几个示例和其他问题,但一定遗漏了一些东西。提前感谢您的帮助。
WCF 服务:
[ServiceContract(Namespace = "http://localhost/")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Items
{
[OperationContract]
[WebGet]
public string HelloWorld()
{
return "Hello World.";
}
}
WCF Web.config
仅相关部分... 服务:
<services>
<service name="OService.ReadServices.Items">
<endpoint address="soap" binding="basicHttpBinding" contract="OService.ReadServices.Items"/>
<endpoint address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="OService.ReadServices.Items"/>
</service>
</services>
行为:
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
jQuery
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost/OService/ReadServices/Items.svc/json/HelloWorld",
data: "{}",
dataType: "json",
success: function (msg) {
alert("success: " + msg.d);
},
error: function (xhr, textStatus, errorThrown) {
alert("error: " + textStatus + " - " + errorThrown + " - " + xhr);
}
});
});
【问题讨论】:
-
检查 FireBug 中的响应(Firefox 插件)