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); }