前台:

    <script language="javascript" src="../js/jquery-1.8.2.js"></script>
<script language="javascript" src="../js/locationFilter.js"></script> <tr>
<td class="fieldtitle" width="20%">
Test Filter:
</td>
<td class="fieldtitle" colspan="3">
<asp:DropDownList ID="ddlRegion" runat="server" CssClass="fieldList" onchange="initData('subregion')">
</asp:DropDownList>
<asp:DropDownList ID="ddlSubRegion" runat="server" CssClass="fieldList" onchange="initData('grid')">
</asp:DropDownList>
<asp:DropDownList ID="ddlGrid" runat="server" CssClass="fieldList" onchange="initData('pref')">
</asp:DropDownList>
<asp:DropDownList ID="ddlPref" runat="server" CssClass="fieldList" onchange="initData('city')">
</asp:DropDownList>
<asp:DropDownList ID="ddlCity" runat="server" CssClass="fieldList" onchange="initData('county')">
</asp:DropDownList>
<asp:DropDownList ID="ddlCounty" runat="server" CssClass="fieldList" onchange="initData('town')">
</asp:DropDownList>
<asp:DropDownList ID="ddlTown" runat="server" CssClass="fieldList" onchange="initData('village')">
</asp:DropDownList>
<asp:DropDownList ID="ddlVillage" runat="server" CssClass="fieldList">
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="txtWWID" runat="server" Style="display: none"></asp:TextBox>
</td>
</tr>

Js文件: locationFilter.js

$(document).ready(function () {
alert(1);
var Rgn_cd = "";
var Subrgn_cd = "";
var Grid_cd = "";
var Pref_cd = "";
var City_id = "";
var County_id = "";
var Town_id = "";
var Village_id = "";
var Type = "region";
var WWID = $("#txtWWID").val(); $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
//url: "MallListCAM.aspx/initData",
url: "../Mall/MallListCAM.aspx/initData",
data: "{rgn_cd:'" + Rgn_cd + "', subrgn_cd:'" + Subrgn_cd + "',grid_cd:'" + Grid_cd + "',pref_cd:'" + Pref_cd + "',city_id:'" + City_id + "',county_id:'" + County_id + "',town_id:'" + Town_id + "',village_id:'" + Village_id + "',type:'" + Type + "',WWID:'" + WWID + "'}",
success: function (data) {
var result = JSON.parse(data.d);
$("#ddlRegion").append($("<option value='ALL'>ALL</option>"));
$("#ddlSubRegion").append($("<option value='ALL'>ALL</option>"));
$("#ddlGrid").append($("<option value='ALL'>ALL</option>"));
$("#ddlPref").append($("<option value='ALL'>ALL</option>"));
$("#ddlCity").append($("<option value='ALL'>ALL</option>"));
$("#ddlCounty").append($("<option value='ALL'>ALL</option>"));
$("#ddlTown").append($("<option value='ALL'>ALL</option>"));
$("#ddlVillage").append($("<option value='ALL'>ALL</option>"));
//clearData("region");
$.each(result, function (i, item) {
$("#ddlRegion").append($("<option value='" + item.rgn_cd + "'>" + item.rgn_nm + "</option>"));
})
},
error: function (err) {
alert("err:" + err);
}
});
}) function initData(type) {
if (type == "subregion") {
clearData("subregion");
}
else if (type == "grid") {
clearData("grid");
}
else if (type == "pref") {
clearData("pref");
}
else if (type == "city") {
clearData("city");
}
else if (type == "county") {
clearData("county");
}
else if (type == "town") {
clearData("town");
} var Rgn_cd = $("#ddlRegion").val();
var Subrgn_cd = $("#ddlSubRegion").val();
var Grid_cd = $("#ddlGrid").val();
var Pref_cd = $("#ddlPref").val();
var City_id = $("#ddlCity").val();
var County_id = $("#ddlCounty").val();
var Town_id = $("#ddlTown").val();
var Village_id = $("#ddlVillage").val();
var Type = type;
var WWID = $("#txtWWID").val(); $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "../Mall/MallListCAM.aspx/initData",
data: "{rgn_cd:'" + Rgn_cd + "', subrgn_cd:'" + Subrgn_cd + "',grid_cd:'" + Grid_cd + "',pref_cd:'" + Pref_cd + "',city_id:'" + City_id + "',county_id:'" + County_id + "',town_id:'" + Town_id + "',village_id:'" + Village_id + "',type:'" + Type + "',WWID:'" + WWID + "'}",
success: function (data) {
var result = JSON.parse(data.d); if (type == "subregion") {
$.each(result, function (i, item) {
$("#ddlSubRegion").append($("<option value='" + item.subrgn_cd + "'>" + item.subrgn_nm + "</option>"));
})
}
else if (type == "grid") {
$.each(result, function (i, item) {
$("#ddlGrid").append($("<option value='" + item.grid_cd + "'>" + item.grid_nm + "</option>"));
})
}
else if (type == "pref") {
$.each(result, function (i, item) {
$("#ddlPref").append($("<option value='" + item.pref_cd + "'>" + item.pref_nm + "</option>"));
})
}
else if (type == "city") {
$.each(result, function (i, item) {
$("#ddlCity").append($("<option value='" + item.city_id + "'>" + item.name + "</option>"));
})
}
else if (type == "county") {
$.each(result, function (i, item) {
$("#ddlCounty").append($("<option value='" + item.county_city_id + "'>" + item.county_name + "</option>"));
})
}
else if (type == "town") {
$.each(result, function (i, item) {
$("#ddlTown").append($("<option value='" + item.town_city_id + "'>" + item.town_name + "</option>"));
})
}
else if (type == "village") {
$("#ddlVillage").empty();
$("#ddlVillage").append($("<option value='ALL'>ALL</option>"));
$.each(result, function (i, item) {
$("#ddlVillage").append($("<option value='" + item.village_city_id + "'>" + item.village_city_id + "</option>"));
})
}
},
error: function (err) {
alert("err:" + err);
}
});
} function clearData(type) {
if (type == "subregion") {
$("#ddlSubRegion").empty();
$("#ddlSubRegion").append($("<option value='ALL'>ALL</option>"));
$("#ddlGrid").empty();
$("#ddlGrid").append($("<option value='ALL'>ALL</option>"));
$("#ddlPref").empty();
$("#ddlPref").append($("<option value='ALL'>ALL</option>"));
$("#ddlCity").empty();
$("#ddlCity").append($("<option value='ALL'>ALL</option>"));
$("#ddlCounty").empty();
$("#ddlCounty").append($("<option value='ALL'>ALL</option>"));
$("#ddlTown").empty();
$("#ddlTown").append($("<option value='ALL'>ALL</option>"));
$("#ddlVillage").empty();
$("#ddlVillage").append($("<option value='ALL'>ALL</option>"));
}
else if (type == "grid") {
$("#ddlGrid").empty();
$("#ddlGrid").append($("<option value='ALL'>ALL</option>"));
$("#ddlPref").empty();
$("#ddlPref").append($("<option value='ALL'>ALL</option>"));
$("#ddlCity").empty();
$("#ddlCity").append($("<option value='ALL'>ALL</option>"));
$("#ddlCounty").empty();
$("#ddlCounty").append($("<option value='ALL'>ALL</option>"));
$("#ddlTown").empty();
$("#ddlTown").append($("<option value='ALL'>ALL</option>"));
$("#ddlVillage").empty();
$("#ddlVillage").append($("<option value='ALL'>ALL</option>"));
}
else if (type == "pref") {
$("#ddlPref").empty();
$("#ddlPref").append($("<option value='ALL'>ALL</option>"));
$("#ddlCity").empty();
$("#ddlCity").append($("<option value='ALL'>ALL</option>"));
$("#ddlCounty").empty();
$("#ddlCounty").append($("<option value='ALL'>ALL</option>"));
$("#ddlTown").empty();
$("#ddlTown").append($("<option value='ALL'>ALL</option>"));
$("#ddlVillage").empty();
$("#ddlVillage").append($("<option value='ALL'>ALL</option>"));
}
else if (type == "city") {
$("#ddlCity").empty();
$("#ddlCity").append($("<option value='ALL'>ALL</option>"));
$("#ddlCounty").empty();
$("#ddlCounty").append($("<option value='ALL'>ALL</option>"));
$("#ddlTown").empty();
$("#ddlTown").append($("<option value='ALL'>ALL</option>"));
$("#ddlVillage").empty();
$("#ddlVillage").append($("<option value='ALL'>ALL</option>"));
}
else if (type == "county") {
$("#ddlCounty").empty();
$("#ddlCounty").append($("<option value='ALL'>ALL</option>"));
$("#ddlTown").empty();
$("#ddlTown").append($("<option value='ALL'>ALL</option>"));
$("#ddlVillage").empty();
$("#ddlVillage").append($("<option value='ALL'>ALL</option>"));
}
else if (type == "town") {
$("#ddlTown").empty();
$("#ddlTown").append($("<option value='ALL'>ALL</option>"));
$("#ddlVillage").empty();
$("#ddlVillage").append($("<option value='ALL'>ALL</option>"));
}
}

后台代码:

[System.Web.Services.WebMethod]
public static string initData(string rgn_cd, string subrgn_cd, string grid_cd, string pref_cd, string city_id, string county_id, string town_id, string village_id, string type, string WWID)
{
//string rgn_cd,string subrgn_cd,string grid_cd,string pref_cd,string city_id,string county_id,string town_id,string village_id,
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["DSN"].DecodeBase64()); SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "region_subregion_grid_pref_city_county_town_village_by_wwid";
cmd.Connection = conn; if (string.IsNullOrEmpty(rgn_cd) || rgn_cd == "null" || rgn_cd == "ALL")
{
cmd.Parameters.AddWithValue("@rgn_cd", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@rgn_cd", rgn_cd);
} if (string.IsNullOrEmpty(subrgn_cd) || subrgn_cd == "null" || subrgn_cd == "ALL")
{
cmd.Parameters.AddWithValue("@subrgn_cd", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@subrgn_cd", subrgn_cd);
} if (string.IsNullOrEmpty(grid_cd) || grid_cd == "null" || grid_cd == "ALL")
{
cmd.Parameters.AddWithValue("@grid_cd", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@grid_cd", grid_cd);
} if (string.IsNullOrEmpty(pref_cd) || pref_cd == "null" || pref_cd == "ALL")
{
cmd.Parameters.AddWithValue("@pref_cd", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@pref_cd", pref_cd);
} if (string.IsNullOrEmpty(city_id) || city_id == "null" || city_id == "ALL")
{
cmd.Parameters.AddWithValue("@city_id", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@city_id", city_id);
} if (string.IsNullOrEmpty(county_id) || county_id == "null" || county_id == "ALL")
{
cmd.Parameters.AddWithValue("@county_id", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@county_id", city_id);
} if (string.IsNullOrEmpty(town_id) || town_id == "null" || town_id == "ALL")
{
cmd.Parameters.AddWithValue("@town_id", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@town_id", town_id);
} if (string.IsNullOrEmpty(village_id) || village_id == "null" || village_id == "ALL")
{
cmd.Parameters.AddWithValue("@village_id", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@village_id", village_id);
}
cmd.Parameters.AddWithValue("@type", type);
cmd.Parameters.AddWithValue("@wwid", "");//((AccessControler)this.Session["_accessctrl"]).GetWWID()); SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd; DataTable dt = new DataTable(); conn.Open();
da.Fill(dt);
//this.HiddenRegion.Text = JsonConvert.SerializeObject(dt); conn.Close();
da.Dispose();
cmd.Dispose(); return JsonConvert.SerializeObject(dt);
}

ajax调用aspx.cs中的WebMethod的更多相关文章

  1. jQuery Ajax 方法调用 Asp.Net WebService 以及调用aspx.cs中方法的详细例子

    一.jQuery Ajax 方法调用 Asp.Net WebService (引自Terry Feng) Html文件 <!DOCTYPE html PUBLIC "-//W3C//D ...

  2. 用juery的ajax方法调用aspx.cs页面中的webmethod方法示例

    juery的ajax调用aspx.cs页面中的webmethod方法:首先在 aspx.cs文件里建一个公开的静态方法,然后加上WebMethod属性,具体实现如下,感兴趣的朋友可以参考下哈,希望对大 ...

  3. 仅用aspx文件实现Ajax调用后台cs程序。(实例)

    仅用aspx文件实现Ajax调用后台cs无刷新程序.(实例) 两个文件:aaa.aspx 和aaa.aspx.cs 一.aaa.aspx <script type="text/java ...

  4. Jquery Ajax调用aspx页面方法

    Jquery Ajax调用aspx页面方法 在asp.net webform开发中,用jQuery ajax传值一般有几种玩法 1)普通玩法:通过一般处理程序ashx进行处理: 2)高级玩法:通过as ...

  5. Jquery Ajax调用aspx页面方法 (转载)

    在asp.net webform开发中,用jQuery ajax传值一般有几种玩法 1)普通玩法:通过一般处理程序ashx进行处理: 2)高级玩法:通过aspx.cs中的静态方法+WebMethod进 ...

  6. jquery.ajax请求aspx和ashx的异同 Jquery Ajax调用aspx页面方法

    1.jquery.ajax请求aspx 请求aspx的静态方法要注意一下问题: (1)aspx的后台方法必须静态,而且添加webmethod特性 (2)在ajax方法中contentType必须是“a ...

  7. 用juery的ajax方法调用aspx.cs页面中的webmethod方法

    首先在 aspx.cs文件里建一个公开的静态方法,然后加上WebMethod属性. 如: [WebMethod] public static string GetUserName() { //.... ...

  8. 项目中Ajax调用ashx页面中的Function的实战

    前台页面: 使用几个display=none的空间存储DropdownList中的值,点击Search Button后刷新页面再次给DropdownList赋值使用 <%@ Page Langu ...

  9. asp.net Ajax调用Aspx后台方法

    Ajax调用的前提(以aspx文件为例:) 1.首先需要在aspx文件后台中引用using System.Web.Services; 2.需要调用的方法必须是公共的(public).静态的(stati ...

随机推荐

  1. top命令详解(转,详细)

    来源:脚本之家(http://www.jb51.net/article/40807.htm) 本文通过一个运行中的WEB服务器的top监控截图,讲述top视图中的各种数据的含义,还包括视图中各进程(任 ...

  2. SQL JOINS

  3. OC-苹果官方文档

    苹果官方文档 help>documentation>左边iOS>language>objective>the objective-c programming langua ...

  4. 一些总结application和事务

    如果需要添加一个全局变量的话  放到application中,但是这个变量中的值要修改的话,必须重新设置application里的值,要不就得重启服务器. String SiteName = (Str ...

  5. 【8-30】oracle数据库学习

    oracle安装:将两个文件合并 全局用户:achievec 口令:Admin123456 用户:scott 口令:tiger oracle开发工具: sqlplusw 和sqlplus和pl/sql ...

  6. angular $resource模块

    目录(?)[-] 安装 应用resource 扩展resource   上一篇中讲到使用$http同服务器进行通信,但是功能上比较简单,angularjs还提供了另外一个可选的服务$resource, ...

  7. Java-Linux系统中搭建开发环境

    准备工作: 0.虚拟机中的系统→{RHEL-I386} 1.JDK→{首先要知道下载哪个版本" [zf@string ~]$ getconf LONG_BIT ":".t ...

  8. codevs4096 删数问题

    题目描述 Description 键盘输入一个高精度的正整数N,去掉其中任意S个数字后剩下的数字按原左右次序将组成一个新的正整数.编程对给定的N 和S,寻找一种方案使得剩下的数字组成的新数最小. 输入 ...

  9. js文字滚动

      <style type="text/css">  #gongao{width:1000px;height:30px;overflow:hidden;line-hei ...

  10. php数据结构与算法

    php面试题之二--数据结构和算法(高级部分) 二.数据结构和算法 1.使对象可以像数组一样进行foreach循环,要求属性必须是私有.(Iterator模式的PHP5实现,写一类实现Iterator ...