前台:

    <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. 分布式消息队列RocketMQ部署

    一.RocketMQ简介: RocketMQ是一款分布式.队列模型的消息中间件,具有以下特点: 1.支持严格的消息顺序: 2.支持Topic与Queue两种模式: 3.亿级消息堆积能力: 4.比较友好 ...

  2. C-函数与内存剖析

    功能,封装,调用 形参:定义函数时函数名后面中的参数,形式参数 实参:调用函数时传入的具体数据 return作用:1退出函数 2返回一个具体数值给调用者 返回值: 如果不明确声明返回值类型,默认就是i ...

  3. http的六种请求方法

    1.get: GET可以说是最常见的了,它本质就是发送一个请求来取得服务器上的某一资源.资源通过一组HTTP头和呈现数据(如HTML文本,或者图片或者视频等)返回给客户端.GET请求中,永远不会包含呈 ...

  4. js jquery, jquery-ui 获取form各种表单input的值?

    如何获取? make up (for): 弥补, 补偿, her beaty cannot make up for her stu'pidity. five Basic laws of human s ...

  5. codeforces #270 ABCD

    Codeforces Round #270 A - Design Tutorial: Learn from Math 题意:给出n,求出两个合数x和y使x+y=n. 题解:暴力筛合数,然后暴力找 // ...

  6. SQLite初试...

    string dataPath = "../../UserData.dbx"; //System.IO.Directory.GetCurrentDirectory() + &quo ...

  7. Hadoop 之面试题

    颜色区别: 蓝色:hive,橙色:Hbase.黑色hadoop 请简述hadoop怎样实现二级排序. 你认为用Java,Streaming,pipe 方式开发map/reduce,各有哪些优缺点: 6 ...

  8. 原生js实现简单打字机效果

    快过年了,公司基本没活,闲着也是闲着,就写了一个 打字机效果玩玩,感觉挺有意思的. 具体代码 请参见我的github,请戳这里 预览效果,请戳这里

  9. Android本地数据存储之SQLite关系型数据库 ——SQLiteDatabase

    数据库的创建,获取,执行sql语句: 框架搭建:dao 思考: 1.数据库保存在哪里? 2.如何创建数据库?如何创建表? 3.如何更新数据库?如何更改表的列数据? 4.如何获取数据库? 5.如何修改数 ...

  10. 淘宝(阿里百川)手机客户端开发日记第一篇 android 主框架搭建(一)

    android 主框架搭建(一) 1.开发环境:Android Studio 相继点击下一步,直接项目建立完毕(如下图) 图片看的效果如果很小,请放大您的浏览器显示百分比  转载请注明http://w ...