
Untitled
By: a guest on
May 22nd, 2012 | syntax:
None | size: 1.27 KB | hits: 16 | expires: Never
Error with Ajax-Enabled WCF Service (JSON) when consuming from jquery .ajax()
[ServiceContract(Namespace = "http://localhost/")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Items
{
[OperationContract]
[WebGet]
public string HelloWorld()
{
return "Hello World.";
}
}
<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>
$(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);
}
});
});