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

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