运用ajax提示未定义
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Ajax.Utility.RegisterTypeForAjax(typeof(AjaxSample.DemoMethods));
}
html :
function GetMac()
{
var send1 = document.getElementById( "send1 ").value
document.getElementById( "send2 ").value=DemoMethods.GetCustomerMac(send1).value
}
namespace AjaxSample
{
public class DemoMethods
{
[Ajax.AjaxMethod]
public string GetCustomerMac(string send)
{
return send*5;
}
运行时提示‘DemoMethods‘未定义
谁能帮我解决一下
[解决办法]
在Web.config文件的 <System.Web> </System.Web> 里加入:
<httpHandlers>
<add verb= "* " path= "*.ashx " type= "AjaxPro.AjaxHandlerFactory,AjaxPro.2 "/>
</httpHandlers>
[解决办法]
document.getElementById( "send2 ").value=DemoMethods.GetCustomerMac(send1).value
里的DemoMethods改为AjaxSample.DemoMethods
[解决办法]
我这段放到config 里面
<httpHandlers>
<remove verb= "* " path= "*.asmx "/>
<add verb= "* " path= "*.asmx " validate= "false " type= "Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 "/>
<add verb= "* " path= "*_AppService.axd " validate= "false " type= "System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 "/>
<add verb= "GET,HEAD " path= "ScriptResource.axd " type= "System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 " validate= "false "/>
</httpHandlers>
[解决办法]
我也遇到了同样的问题,不过 whw123456 的办法帮我解决了。LZ 看你的代码应该把命名空间也写上:
function GetMac()
{
var send1 = document.getElementById( "send1 ").value
document.getElementById( "send2 ").value=AjaxSample.DemoMethods.GetCustomerMac(send1).value
}
还有再在webconfig中把 whw123456 说的在加上。
whw123456 多谢,我一会开个帖子,把我的代码贴出来,你来随便回给贴。我把分给你,表示感谢。