zoukankan      html  css  js  c++  java
  • ashx 文件 与js文件数据交互

    //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());
     
     
            }
        }
  • 相关阅读:
    查找mysql数据库中所有包含特定名字的字段所在的表
    redis在windows下安装和PHP中使用
    CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境
    telnet: connect to address 127.0.0.1: Connection refused
    [Java]局域网五子棋
    springboot-web进阶(三)——统一异常处理
    springboot-web进阶(二)——AOP统一处理请求
    springboot-web进阶(一)——表单验证
    springboot快速入门(五)——事务管理
    springboot快速入门(四)——数据库操作
  • 原文地址:https://www.cnblogs.com/jf-guo/p/3927378.html
Copyright © 2011-2022 走看看