我的脚本管理器的属性 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"/>