为什么这个页面方法失败了?
我的脚本管理器的属性 enablepagemethods 设置为 true,但是,由于某种原因,这提醒我失败了。
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod()]
public static string test()
{
return "q343242342342";
}
}
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function callMethod() {
PageMethods.test(onSuccess, onFailure);
}
function onSuccess(result) {
alert(result.d);
}
function onFailure(error) {
alert('fail');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
</asp:ScriptManager>
<div>
<asp:Button ID="Button1" OnClientClick="callMethod()" runat="server" Text="Button"/>
I have my script manager with attribute enablepagemethods set to true, however, for some reason this is alert me I've failed.
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod()]
public static string test()
{
return "q343242342342";
}
}
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function callMethod() {
PageMethods.test(onSuccess, onFailure);
}
function onSuccess(result) {
alert(result.d);
}
function onFailure(error) {
alert('fail');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
</asp:ScriptManager>
<div>
<asp:Button ID="Button1" OnClientClick="callMethod()" runat="server" Text="Button"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码对我有用 - 无法准确判断您的问题出在哪里,但您在 runat=server 块中没有代码(假设您只是从后面的代码复制)。但我认为这个确切的代码应该有效。
This code worked for me - can't exactly tell where your issue is bu you don't have your code in a runat=server block (assuming you are just copying from code behind maybe). But this exact code should work - I think.