ajax 调用失败!!
快疯了!调试了很久还是不行!!
请各位大侠帮帮看一下!
aspx内容:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AjaxTest</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="test()"/>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
<script language="javascript" type="text/javascript">
function test()
{
PageMethods.getServerValue(onSucess());
}
function onSucess(result)
{
alert(result);
}
</script>
cs代码内容:
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void tbClick(object sender, EventArgs e)
{
Label1.Text = "new hah ";
}
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
[WebMethod(true)]
public static string getServerValue()
{
return "test";
}
}
代码很简单,就是用js脚本调用后代getServerValue函数!!
可是用"alert(PageMethods.getServerValue(onSucess()))"测试返回的内容的是一只是undefined,不知道该怎么修改!!!!
万分感谢!!