后台handler.ashx
<%@ webhandler language="c#" class="handler" %> using system; using system.web; using system.data; public class handler : ihttphandler { common coobj = new common(); public void processrequest(httpcontext context) { if (context.request.params[n] != null) { string num = context.request.params[n].tostring(); context.response.contenttype = text/plain; string str = select * from address where a_num2= + num; datatable dt = coobj.gettable(str); string json = jsonhelper.datatabletojson(dt); context.response.write(json); } } public bool isreusable { get { return false; } } }
前台dropdownlist.html
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <title>dropdownlit </title> <meta name="generator" content="editplus" /> <script type="text/javascript" src="js/jquery-1.5.2.js"></script> <script type="text/javascript"> $(function(){ initdata(0); }); function initdata(n) { $.ajax({ type:post, datatype:json, url: handler.ashx, data:{n:n}, success:function(json){ $.each(json,function(i,n){ var pro=$(#dl1); $(+ n.a_name +).appendto(pro); }); } }); } function getcity(n) { var city=$(#dl2); city.html(); $.ajax({ type:post, datatype:json, url: handler.ashx, data:{n:n}, success:function(json){ $.each(json,function(i,n){ $(+ n.a_num1 +>+ n.a_name +).appendto(city); }); } }); } </script> </head> <body> <select id="dl1" onchange="getcity(this.value)"> </select> <select id="dl2"> </select> </body> </html>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
jquery监控文本框事件并处理步骤详解
ajax使用代理,jsonp,xhr2实现跨域
以上就是ajax二级联动有哪些实现方法的详细内容。
