jq ajax 联动无刷新

<script type="text/javascript" language="javascript">

         $(document).ready(function () {
           $("#bigclass").change(function () {
               BindDropDownList();

           });
       });


       function BindDropDownList() {
           $("#smallclass").html("");
           var bigid = $("#bigclass").attr("value");
           $.getJSON("GetDate.ashx?useclass="+bigid,function(json){//传值到GetData.ashx页面
               $.each(json, function (i) {
                   $("#smallclass").append($("<option ></option>").val(json[i].id).html(json[i].name))
               });
           });
       }
        </script>
 public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string idd = context.Request.Params["useclass"];
            id1 = Int32.Parse(idd);
            //context.Response.Write("Hello World");
            BLL.FrontDesk.actbll actbll = new BLL.FrontDesk.actbll();
            maitte(); bindGroup();
            string str = "[";
            int i = 0;
            DataTable dt = dsz.Tables[0];
            if (dt != null)
            {
                //找到选择的区域
                foreach (DataRow row in dt.Rows)
                {
                    string usefulInformation = row["name"].ToString();
                    str += "{" + "\"" + "id" + "\"" + ":";
                    str += "\"" + row["id"].ToString() + "\"" + ",";
                    str += "\"" + "name" + "\"" + ":";
                    str += "\"" + usefulInformation.ToString() + "\"";
                    if (i == dt.Rows.Count - 1) //判断是否是最后一条记录
                        str += "}]";
                    else
                        str += "},";

                    i += 1;
                }
            }
            context.Response.ContentType = "application/json";
            context.Response.ContentEncoding = System.Text.Encoding.UTF8;

            context.Response.Write(str.ToString());
        }

 

posted @ 2012-01-08 11:27  冰灵的风儿  阅读(155)  评论(0)    收藏  举报