使用ajax.dll时js脚本错误-XXX未定义

操作系统:Windows 7

IIS:7.5

ajax.dll现在用的比较少,但是以前的项目有这个,使用的时候很容易出现这个错误,因为总是会遗漏配置。

使用ajax.dll时,js脚本错误,无法调用后台方法-XXX未定义

使用ajax.dll,首先项目引用ajax.dll,然后在customer类中定义方法

        /// <summary>
        /// 得到用户的信息
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public Model.customer GetUserInfo(int userID)
        {
            Customer customer = new Customer();
            return customer.GetCusInfo(userID);
        }    

 

然后在js中调用此方法,customer.GetUserInfo("userID")

这时js提示customer未定义,解决办法

修改web.config文件

<system.webServer>
        <handlers>
            <add name="ajax" path="ajax/*.ashx" verb="POST,GET" type="Ajax.PageHandlerFactory, Ajax"/>
        </handlers>
</system.webServer>

这样就OK了

posted @ 2013-08-23 22:56  Kenyep  阅读(588)  评论(0编辑  收藏  举报