My initial endeavor to call a server-side function from JavaScript is not yielding results as the webmethod is not being invoked.
Within the aspx file, there is a bootstrap-styled button; upon clicking it, the objective is to append a new entry to the user's "Favorites" list (inserting a record in the database).
The page inherits from a master page which includes:
<asp:ScriptManager runat="server" ID="ScriptManager1" EnablePageMethods="true" />
The aspx page includes:
<script type="text/javascript">
function addFavorite(url, friendly) {debugger
PageMethods.AddFavorite(url, friendly, onSuccess);
}
function onSuccess(result, userContext, methodName) {debugger
alert(result);
}
</script>
<button type="button" class="btn btn-primary btn-xs" onclick="addFavorite('some_url', 'some friendly name');">
<i class="fa fa-heart-o" aria-hidden="true"></i>Favorites</button>
In the code-behind:
[WebMethod]
public static string AddFavorite(string sURL, string sFriendlyName)
{
// This is where a record would be added to a DB table, but for testing ...
return sFriendlyName;
}
Upon clicking the button, addFavorites() is triggered followed immediately by onSuccess, skipping the web method and displaying part of the page source in an alert box.
Despite researching extensively, I'm unable to pinpoint the issue. All examples I've found follow the same steps I've taken.