zoukankan      html  css  js  c++  java
  • 完整的ajax

    error:
    服务器连接不上,或是返回内容有错误,就走这里
    通常可以使用这玩意排错
    beforeSend:
    ajax一执行,就立马执行这个方法

    complete:
    ajax里的success或是error执行完毕,立马执行这里

    跳转界面:window.location.href="";

    三级联动小练习:

    html页

    <select id="sel1">
            <option>加载中...</option>
        </select><select id="sel2">
            <option>加载中...</option>
        </select><select id="sel3">
            <option>加载中...</option>
        </select><script type="text/javascript">
            city($("#sel1"), "0001", '1');
    
            $("#sel1").change(function () {
                city($("#sel2"), $("#sel1").val(), '2');
            });
    
            $("#sel2").change(function () {
                city($("#sel3"), $("#sel2").val(), '3');
            });
    
            function city(sel, code, count) {
                $.ajax({
                    url: "Ashxs/bbbb.ashx",
                    data: { "code": code },
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        sel.empty();
                        for (i in data) {
                            sel.get(0).add(new Option(data[i].name, data[i].code));
                        }
                        if (count == '1')
                        {
                            aaaa($("#sel2"), $("#sel1").val(),'2');
                        }
                        if (count == '2')
                        {
                            aaaa($("#sel3"), $("#sel2").val(), '3');
                        }
                    }//success
                });//ajax
            }//封装方法
    
        </script>

    一般处理程序

       datauserDataContext con = new datauserDataContext();
    
        public void ProcessRequest(HttpContext context)
        {
            string end = "[";
            int count = 0;
    
            string code = context.Request["code"];
    
            List<ChinaStates> list = con.ChinaStates.Where(r => r.ParentAreaCode == code).ToList();
    
            if (list.Count > 0)
            {
                foreach (ChinaStates c in list)
                {
                    if (count <= 0)
                    {
                        end += "{"name":"" + c.AreaName + "","code":"" + c.AreaCode + ""}";
                    }
                    else
                    {
                        end += ",{"name":"" + c.AreaName + "","code":"" + c.AreaCode + ""}";
                    }
                    count++;
                }
            }
    
            end += "]";
            context.Response.Write(end);
        }
  • 相关阅读:
    五层原理体系结构的简单分析
    Simple Factory 简单工厂模式(静态工厂)
    css一个图片包含多个图片|网站侧栏导航
    百度地图、高德地图的数据从哪里得到的?
    浏览器开发
    开发一款浏览器内核需要学习哪些方面的知识?
    使用PowerDesigner进行数据库建模入门
    How to create a search engine
    合并两个有序数组
    STL中的algorithm
  • 原文地址:https://www.cnblogs.com/sunshuping/p/5837389.html
Copyright © 2011-2022 走看看