Reputation: 6260
I have a simple enough web service:
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public string GetToken(string a)
{
}
And I'm calling it client side using JQuery:
$.ajax({
post: 'GET',
contentType: "application/json; charset=utf-8",
dataType: 'json',
url: '../url/GetToken',
data: "{'a':'test'}",
success: function (data) {
},
error: function (a, b, c) {
}
});
The call always fails and the error returned is 500 Internal Server Error. I have placed a breakpoint inside the web service, and the code isn't being reached at all. When I modify the web service to take no arguments at all (and remove the data
element from the JQuery call) the call succeeds. I have played around with different ways to pass the data
element; I've passed a JSON object (no quotes), and I've removed the quotes from around the a
argument. None of it works.
Using Fiddler I have determined that the actual error causing the 500 is "Invalid web service call, missing value for parameter".
Passing data this way works:
data: "a='test'"
I have no idea why. Any ideas?
Upvotes: 2
Views: 11232
Reputation: 543
Haven't tested this, but in your code snippet you have post: 'GET'
rather than type: 'GET'
. That may be causing the server to reject the contentType as json (which is why your data isn't being serialized properly).
Upvotes: 3
Reputation: 1653
I couldn't use the GET, had to use POST as type, and my web service is in the same directory, but this worked:
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: 'json',
url: 'url.asmx/GetToken',
data: "{'a':'test'}",
success: function(data) {
alert("Success");
},
error: function(a) {
alert(a.responseText);
}
});
Upvotes: 2
Reputation: 860
You could use a tool like Fidler to check the response you are getting back. Most likely there is an error page being returned, but since it is a jquery ajax call you are not seeing it.
Upvotes: 2