关于AjaxPro的问题

kyo22874515 2009-03-12 05:19:55
获得不到数据,

前端

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxProTest.aspx.cs" Inherits="AjaxProTest" %>

<!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 runat="server">
<title>AjaxPro测试</title>
<script type="text/javascript" language="javascript">
function GetPoliceList(id)
{
var result = AjaxProTest.GetPoliceSet(id);
var DropDownList = document.getElementById('DropSecond');
DropDownList.length = 0;
for(var i=0;i<result.length;i++)
{
DropDownList.options.add(new Option(result.Rows[i].note,result.Rows[i].code));
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropFirst" runat="server" onchange="GetPoliceList(document.getElementById('DropFirst').value)">
</asp:DropDownList>

<asp:DropDownList ID="DropSecond" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
</html>


后端

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class AjaxProTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxProTest));//注册Ajax可调用的类的名称

if (!IsPostBack)
{
string sql = "SELECT CODE,NOTE FROM SM_AREA";
DataSet Area_Set = SqlExec.ExecuteDataset(sql);
DropFirst.DataSource = Area_Set.Tables[0].DefaultView;
DropFirst.DataValueField = "CODE";
DropFirst.DataTextField = "NOTE";
DropFirst.DataBind();
DropFirst.Items.Insert(0,new ListItem("---请选择---", ""));

string sql1 = "SELECT CODE,NOTE FROM SM_POLICE";
DataSet Police_Set = SqlExec.ExecuteDataset(sql1);
DropSecond.DataSource = Police_Set.Tables[0].DefaultView;
DropSecond.DataValueField = "CODE";
DropSecond.DataTextField = "NOTE";
DropSecond.DataBind();
DropSecond.Items.Insert(0, new ListItem("---请选择---", ""));

}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}

[AjaxPro.AjaxMethod]
public DataTable GetPoliceSet(string AREACODE)
{
try
{
string sql = "SELECT CODE,NOTE,AREACODE FROM SM_POLICE WHERE AREACODE = '" + AREACODE + "'";
DataSet dataset = SqlExec.ExecuteDataset(sql);
return dataset.Tables[0];
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
return null;
}
}



web.config

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>

<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
...全文
76 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
a260881071 2009-03-19
  • 打赏
  • 举报
回复
erytbc 2009-03-14
  • 打赏
  • 举报
回复
var result = AjaxProTest.GetPoliceSet(id);

换成
var result = AjaxProTest.GetPoliceSet(id).value;


行不?

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧