Reputation: 29727
Ive got asmx handler file with cs class.
When I enter mysite/myService.asmx?op=Test nice page is rendered and I can invoke my web method without any problems but when I try to do it from javascript I can see in firebug 500 error as a responce. I put breakpoint on the server side inside that web.method but it wasnt even invoked.
what am I doing wrong ?
Class Declaration:
[System.Web.Script.Services.ScriptService]
public partial class WebServiceDB : System.Web.Services.WebService {
Web.Method:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Test()
{
return "test";
}
JS:
$.ajax({
url: "mysite/myService.asmx?op=Test",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (msg) {
alert("ok");
},
error: function (e) {
alert("error");
}
});
Thanks for help
Upvotes: 0
Views: 1693
Reputation: 445
When you enter a URL in the browser, you are performing a GET request. However, your $.ajax
request is using POST. Given the lack of much other context, that would be my first suspicion as where the problem is. Try changing type: "POST"
to type: "GET"
Upvotes: 1