Use the browser's dev tools (f12) or Fiddler to examine the network traffic as it will often reveal the actual error. You need to mark your webservice as a script service
[System.Web.Script.Services.ScriptService]
public class testservice : System.Web.Services.WebService
{
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string _testserv(string userid, string password)
{
return "Hello World";
}
}
$.ajax
({
type: "POST",
url: "testservice.asmx/_testserv",
data: "{'userid':'" + userid + "','password': '" + txtpwd + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function (ex) {
alert(ex.toString());
}
});