1. 引用ajaxPro2.dll到你的工程中。
2. 在Web.config中添加配置
<httpHandlers>
       <add path="ajaxpro/*.ashx" verb="POST,GET" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2" />
   </httpHandlers>
3. 在程序中注冊Ajax
protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(filejob_DCFCS01));
    }
……
[AjaxPro.AjaxMethod]
    public string[] GetOldInfo(string No)
    {
            String [] strret=new string[5];
            ……
            Return strret;
        }
4. 在客戶端的調用
<asp:TextBox ID="tbxODANo" runat="server" CSSClass="Input" MaxLength="7" Width="134px" onchange=”getInfo(this);”></asp:TextBox>
<script type=”text/javascript”>
Function getInfo(oda)
{
        Var no=oda.value;
        filejob_DCFCS01. GetOldInfo(no,callback);//異步方法
}
Function callback(res)
{
     If(res.error)
        Alert(“錯誤”);
     Else
    {
    Alert(Res.value[0]);
}
}
 可以把Ajax要操作的方法放到一個Ajax操作類里
Public class AjaxMethod
{
  [Ajax.AjaxMethod]
  public static string[] GetOldInfo(string No)
    {
                  String [] strret=new string[5];
                  ……
                  Return strret;
          }
}

在調用時要注冊Ajax:
AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxMethod));
5. AjaxPro方法返回DataSet
只能在同步ajax時才能返回DataSet 類型
Public class AjaxMethod
{
[Ajax.AjaxMethod]
 public static DataSet GetOldInfo(string No)
{
     ……
   Return ds;
}
}
在客戶端取DataSet數據:
Function getInfo()
{
 Var res= AjaxMethod. GetOldInfo(oda.value).value; //同步調用
 If(ds!=null)
{
  Var dt=ds.Tables[0];
Var rows=dt.Rows.length;
For(var i=0;i<rows;i++)
{
 Document.write(dt.Rows[i][dt.Columns[0].name]);
}
}
}
 新闻热点
疑难解答