日期:2014-05-18  浏览次数:20469 次

ajax问题请高手们指教(.NET2005)
前台:
function   ajaxTest()
{
        Method.testx(document.getElementById( "txt1 ").value,getStr);
        //popmsg(document.getElementById( "txt2 ").value);
}
function   getStr(str)
{
        document.getElementById( "txt2 ").value   =   str.value;
}
-------------------------------
后台:
[Ajax.AjaxMethod]
public   static   string   testx(string   id)
{
        SqlConnection   sqlconn   =   new   SqlConnection( "Server=(local);DataBase=NET2005TEST;UID=sa;PWD=liveflow ");
        SqlDataAdapter   ada   =   new   SqlDataAdapter( "select   *   from   DATASHOW   where   USERID   =   ' "   +   id   +   " ' ",   sqlconn);
        DataTable   dt   =   new   DataTable();
        ada.Fill(dt);
        sqlconn.Close();

        string   str   =   " ";
        try
        {
                for   (int   i   =   0;   i   <   dt.Columns.Count;   i++)
                {
                        if   (str.Equals( " "))
                        {
                                str   =   dt.Rows[0][i].ToString();
                        }
                        else
                        {
                                str   +=   "; "   +   dt.Rows[0][i].ToString();  
                        }
                }
                return   str;
        }
        catch   (Exception   ex)
        {
                return   " ";
        }
}
--------------------------------
总是报Method未定义,请各位高手解救。

------解决方案--------------------
1。 首先:webconfig里面的配置保证是正确的
2。 其次:Page_Load里面加上注册信息
3。 Ajax.Method方法保证正确

------解决方案--------------------
<add path= "*.ashx " verb= "* " type= "AjaxPro.AjaxHandlerFactory,AjaxPro.2 "/>
AjaxPro.Utility.RegisterTypeForAjax(typeof(页面类))