I attempted to create a basic web method that can be accessed from JavaScript, but unfortunately I am encountering difficulties.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(
function test() {
var x = PageMethods.MyMethod();
alert(x.toString());
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
</asp:ScriptManager>
</div>
</form>
</body>
</html>
The code behind is as follows:
[WebMethod]
public static string MyMethod()
{
return "Hello";
}
The variable x appears to be null. I am struggling to identify the issue. Any assistance or guidance would be greatly appreciated. Thank you in advance.