在网络上下载了ajax实现dropdownlist无刷新代码,自己做了修改,出现了这样一个问题:当使用Visual Studio调试时(如http://localhost:50242/Ajax-DropDownList/Default.aspx)一切正常(点击第一个下拉框后两个下拉框能实现无刷新修改),当使用IIS发布时(发布后网址为http://127.0.0.1/Ajax-DropDownList/Default.aspx)点击第一个下拉框却提示'AjaxMethod' 未定义,怎么也想不明白为什么,请高手赐教
附上数据库和源代码。
http://d.namipan.com/d/ccce4093b66a9e6ea3435b8fccc5e98008b88cf689140400
我的环境是Windows 7,Visual Studio 2008,使用IIS发布的时候是在Default Web Site上右键添加的应用程序。

解决方案 »

  1.   

    AjaxMethod未定义原因 原因:是命名空间的问题
    注意事项:1.
    pageload()方法中
    AjaxPro.Utility.RegisterTypeForAjax(typeof(WebApplication2.AjaxMethod));
    2.
    AjaxMethod类中
    [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]3.
    web.config中
    <httpHandlers>
            <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
          </httpHandlers> 
    4.global.asax的Application_Start方法中AjaxPro.Utility.HandlerPath = "ajaxpro"; 
      

  2.   

    http://www.web3.cn/Content,2006,6,27,155.aspx
      

  3.   

    首先非常感谢回复
    1.在pageload中引用了Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod));
    2.在AjaxMethod.cs 中添加了[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
    3.web.config中添加了  <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
    4.我的程序中没有global.asax
      

  4.   

    <%...@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>
        <title>web3.cn——Ajax实现无刷新三联动下拉框</title>
        <style type="text/css">... 
            body {...}{COLOR: #333; 
            FONT-SIZE: 9pt; 
            LINE-HEIGHT:150%; 
            FONT-FAMILY: 'Lucida Grande',arial,verdana,sans-serif; }
        </style>
                <script language="javascript">...            
                //城市------------------------------
                function cityResult() 
                ...{ 
                    var city=document.getElementById("DropDownList1");
                    AjaxMethod.GetCityList(city.value,get_city_Result_CallBack);
                }
                
                function get_city_Result_CallBack(response)
                ...{
                    if (response.value != null)
                    ...{                    
                        //debugger;
                        document.all("DropDownList2").length=0;                
                    var ds = response.value;
                        if(ds != null && typeof(ds) == "object" && ds.Tables != null)
                        ...{                    
                            for(var i=0; i<ds.Tables[0].Rows.length; i++)
                        ...{
                            var name=ds.Tables[0].Rows[i].city;
                          var id=ds.Tables[0].Rows[i].cityID;
                          document.all("DropDownList2").options.add(new Option(name,id));
                        }
                        }
                    }                
                    return
                }
                //市区----------------------------------------
                function areaResult() 
                ...{ 
                    var area=document.getElementById("DropDownList2");
                    AjaxMethod.GetAreaList(area.value,get_area_Result_CallBack);
                }
                function get_area_Result_CallBack(response)
                ...{
                    if (response.value != null)
                    ...{                    
                        document.all("DropDownList3").length=0;                
                    var ds = response.value;
                        if(ds != null && typeof(ds) == "object" && ds.Tables != null)
                        ...{                    
                            for(var i=0; i<ds.Tables[0].Rows.length; i++)
                        ...{
                          var name=ds.Tables[0].Rows[i].area;
                          var id=ds.Tables[0].Rows[i].areaID;
                          document.all("DropDownList3").options.add(new Option(name,id));
                        }                
                        }
                    }
                    return
                }
                function getData()
                ...{
                    var province=document.getElementById("DropDownList1");
                    var pindex = province.selectedIndex;
                    var pValue = province.options[pindex].value;
                    var pText  = province.options[pindex].text;
                    
                    var city=document.getElementById("DropDownList2");
                    var cindex = city.selectedIndex;
                    var cValue = city.options[cindex].value;
                    var cText  = city.options[cindex].text;
                    
                    var area=document.getElementById("DropDownList3");
                    var aindex = area.selectedIndex;
                    var aValue = area.options[aindex].value;
                    var aText  = area.options[aindex].text;
                    
                    var txt=document.getElementById("TextBox1");                                                document.getElementById("<%=TextBox1.ClientID%>")
                    .innerText="省:"+pValue+"|"+pText+"市:"+cValue+"|"+cText+"区:"+aValue+"|"+aText;
                }
                </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <table cellspacing="0" border="1" style="width:300px;border-collapse:collapse;background:#ececec;">
            <tr>
                <td>省市</td>
                <td><asp:dropdownlist id="DropDownList1" runat="server"></asp:dropdownlist></td>
            </tr>
            <tr>
                <td>城市</td>
                <td><asp:dropdownlist id="DropDownList2" runat="server"></asp:dropdownlist></td>
            </tr>
            <tr>
                <td>市区</td>
                <td><asp:dropdownlist id="DropDownList3" runat="server"></asp:dropdownlist></td>
            </tr>
        </table>
        <br />
        <asp:TextBox id="TextBox1" runat="server" Width="424px"></asp:TextBox>
        <input type="button" value="获取资料" onclick="getData();" />
        </form>
    </body>
    </html>
      

  5.   

    form 有没有 runat="server" 
    AjaxMethod命名空间是否正确
    三级联动
      

  6.   

    http://www.cnblogs.com/zgqys1980/archive/2006/08/07/469945.aspx
      

  7.   

    谢谢各位的回复,问题还是没有解决,刚刚又下载的小山的代码,也是同样的问题,调试的时候正常,发布后就提示'AjaxMethod' 未定义。
      

  8.   

    http://www.cnblogs.com/oec2003/archive/2009/07/13/1522569.html
      

  9.   


    还是不行,执行到aspx页面的AjaxMethod.GetCityList(city.value, get_city_Result_CallBack);
    就报'AjaxMethod' 未定义function cityResult() 

    var city=document.getElementById("DropDownList1");
    AjaxMethod.GetCityList(city.value, get_city_Result_CallBack);
    }
      

  10.   

    找到原因了,下需要在<system.webServer><handlers>增加
    <add name="POST,GET"  verb="*" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>就OK了,是<handlers>,不是<httpHandlers>