码迷,mamicode.com
首页 > Web开发 > 详细

ashx 文件 与js文件数据交互

时间:2014-08-21 16:53:54      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:http   os   io   文件   for   数据   ar   div   

//js代码

//城市下拉列表

            $("#selPro").change(function() {
                var option = "";
                $.ajax({
                    type: "post",
                    url: "homeHandler/HomeProvince.ashx",
                    dataType: "json",
                    data: "proStr=" + $("#selPro").val(),
                    success: function(message) {
                        if (message != null) {
                            $("#selCity option").remove();
                            option += "<option value=\"0\">==请选择==</option>";
                            $.each(message.city, function(i, item) {
                                option += "<option value=\"" + item.id + "\">" + item.name + "</option>";
                            });
                        }
                        $("#selCity").append(option);
                    }
 
                });
 
            });
 
 
//  c#代码
public void ProcessRequest(HttpContext context)
    {
 
        //得到城市Id
        int proId = Convert.ToInt32(context.Request.Params["proStr"]);
        if (proId != 0)
        {
            //根据城市Id查询城市下的区县
            List<City> listCity = CityManager.GetAllByProId(proId);
            int i = 0;
 
            StringBuilder strJSON = new StringBuilder();
            strJSON.Append("{\"city\":[");
            foreach (City city in listCity)
            {
                if (i < (listCity.Count - 1))
                {
                    strJSON.Append("{");
                    strJSON.Append("\"id\":");
                    strJSON.Append(Convert.ToInt32(city.CityId));
                    strJSON.Append(",");
                    strJSON.Append("\"name\":\"");
                    strJSON.Append(city.CityName);
                    strJSON.Append("\"},");
                }
                if (i == (listCity.Count - 1))
                {
                    strJSON.Append("{");
                    strJSON.Append("\"id\":");
                    strJSON.Append(Convert.ToInt32(city.CityId));
                    strJSON.Append(",");
                    strJSON.Append("\"name\":\"");
                    strJSON.Append(city.CityName);
                    strJSON.Append("\"}");
                }
                i++;
            }
           
            strJSON.Append("]}");
            context.Response.Write(strJSON.ToString());
 
 
        }
    }

ashx 文件 与js文件数据交互,布布扣,bubuko.com

ashx 文件 与js文件数据交互

标签:http   os   io   文件   for   数据   ar   div   

原文地址:http://www.cnblogs.com/jf-guo/p/3927378.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!