I am having issues calling an ASP.NET web service in JQuery. I am basically following all the instructions on:
http://www.codeproject.com/Articles/211489/Using-JSON-with-ASP-NET-3-5
I have written the Web service and the console server in C# and ASP.NET.
My JQuery is as follows:
jQuery.support.cors = true;
$.ajax({
type: "POST",
contentType: "application/json; charset=ut-8",
username: "John",
password: "Doe",
url: "https://machinename:8043/WtfService/HelloWorldPostSimple1",
data: '{"firstName":"John"}',
dataType: "json",
success: function(msg) {
alert(msg.d);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR + " : " + textStatus + " : " + errorThrown);
}
});
The first line allows for cross domain calls in IE which works. If I call a web service method that doesn’t accept parameters, it works 100% for GET and POST.
My web service method is as follows:
[WebInvoke(Method = "POST", UriTemplate = "HelloWorldPostSimple1")]
[PrincipalPermission(SecurityAction.Demand, Role = "WtfUser")]
public string HelloWorldPostSimple1(string firstName)
{
return string.Format("Hello {0} {1}", firstName, "Doe");
}
I’ve tried specifically putting in the Request and Response formats as JSON but still no luck.
Thanks a lot everyone.
Turns out utf-8 was spelt wrong 🙁
Thanks Dave Simione for picking that up!