I'm trying to test a function that is on the server side by calling it from the client side using AJAX.
I get this error every time I invoke the AJAX method:
http://localhost:5958/myaccount/notifications/myaccount/notifications/Default.aspx/method Failed to load resource: the server responded with a status of 404 (Not Found)
Here's my AJAX function:
function ShowCurrentTime() {
$.ajax({
type: "POST",
url: "myaccount/notifications/Default.aspx/method",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
HTML control :
<input id="btnGetTime" type="button" value="Show Current Time"
onclick="ShowCurrentTime()" />
Function I'm trying to call on the server side:
[WebMethod]
protected bool method()
{
return true;
}
What's the correct way of doing this?
Update
Changed the url to : '<%= ResolveUrl("~/default.aspx/method") %>'
and now I'm getting 500 Internal Server Error.
Update2
The internal error was due to [HttpPost] attribute which I changed to [WebMethod] and it works.