I have an ASP.NET Web Forms application and on one of my .ASPX pages I have some javascript.
In one part of the Javascript, I want to call a web service so I can perform a server-side function and return either a true or false value, then in the javascript I can perform one of two actions depending on the true or false value.
I've not done any web services before and so I'm struggling with getting a simple value back to the JS.
My WebService (LoginCheck.asmx) currently looks something like this:
[System.Web.Script.Services.ScriptService]
public class LoginCheck : System.Web.Services.WebService
{
[WebMethod]
public bool IsLoggedIn()
{
return UserService.IsAuthenticated();
}
}
My Javascript call currently looks something like this:
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "LoginCheck.asmx/IsLoggedIn",
data: "{}",
dataType: "json",
success: function (response) {
if (response) {
alert('Logged in: true');
} else {
alert('Logged in: false');
}
}
});
Despite having a breakpoint in my code on the 'IsLoggedIn' web service method, it never breaks on it. I have checked the 'console' in Google Chrome when the web service is supposed to be called and it says something along the lines of:
"The following operations are supported...", and it shows my one 'IsLoggedIn' method, but all the content rendered in this console window is essentially an HTML page, with HTML markup.
I don't appear to ever be a) breaking on the breakpoint in code or b) getting a response back to my javascript (hence neither of the js alerts shown in my code above are occurring).