I am working on asp.net web forms application. I am trying to make an ajax call to a web method in codebehind, but instead of returning the result, it returns the whole html page.
I am calling it on button click
<input type="button" id="btnCallAPIFromClient" class="btn btn-success" value="Call API from Client"/>
My js script is:
$(document).ready(function() {
//PageMethods.set_path(PageMethods.get_path() + '.aspx');
$('#btnCallAPIFromClient').click(function() {
alert('here');
$.ajax({
url: '/login/GetAccessToken',
type: "POST",
dataType: 'html',
success: function(response) {
alert(response);
debugger;
sessionStorage.setItem("accessToken", response.access_token);
alert(response.access_token);
},
// Display errors if any in the Bootstrap alert <div>
error: function(jqXHR) {
alert(jqXHR.responseText);
}
});
});
});
webmethod is:
[WebMethod]
public static string GetAccessToken()
{
return "abc";
}