快疯了!调试了很久还是不行!!
请各位大侠帮帮看一下!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,不知道该怎么修改!!!!万分感谢!!

解决方案 »

  1.   

    PageMethods.getServerValue(onSucess); 
      

  2.   

    帮着顶,用webservice形式的Ajax还没用过,不过可能马上要用到。
      

  3.   

    1楼正确<script language="javascript" type="text/javascript"> 
    function test() 

        //onSucess()的括号要去掉
        //PageMethods.getServerValue(onSucess()); 
        PageMethods.getServerValue(onSucess); } function onSucess(result) 

        alert(result); 
    } </script> 
    可是用"alert(PageMethods.getServerValue(onSucess()))"测试返回的内容的是一只是undefined,不知道该怎么修改!!!! 
           --直接alert()它是返回undefined的,因为结果还没返回,异步的,回调onSucess是调用完触发的,所以在onSucess里可以正常alert(result)
      

  4.   

    PageMethods.getServerValue(onSucess); //onSucess后面没有括号
      

  5.   

    PageMethods.getServerValue(onSucess); 
      

  6.   

    这样才是完整的调用方法, 
    PageMethods.getServerValue(id,ischecked,check_CheckedChanged_Success,check_CheckedChanged_Failed); 
    必须有失败与成功的处理函数,你的js 没有写完整,缺少这两个函数,lz 结贴给分吧     
      

  7.   

    UP   为什么     function btnClick(event){
                // 调用页面后台方法,前面跟方法所需的参数,接着是方法回调成功时要执行的js函数,最后一个是方法回调失败时要执行的js函数
                  PageMethods.sss('ss',funReady,funError);
              }        
            // result 就是后台方法返回的数据
            function funReady(result){
               // div1.innerHTML=result;
                alert(result);
                //alert(div1.innerHTML);
            }
            // err 就是后台方法返回的错误信息
            function funError(err){
            
                alert("Error:" + err._message );
            }
            function iniCooke()
            {
              //document.cookie="id=12";;
              
            }
            function readyCooke()
            {
             //var s=document.cookie;
              //div1.innerHTML=s;
            }
    在FF下面可以运行 在IE里面不能运行