Jquery同步之載入數據簡單實例
function getItem() { var str= $.AJax({ url: "Exec.ASPx?flag="+Variables, async: false }).responseText; var dom=new ActiveXObject("Microsoft.XMLDOM"); dom.loadXML(XML); var t=dom.getElementsByTagName("item"); var menu=document.getElementById("Sele_City").options; menu.length=0; for(var i=0;i<t.length;i++) { menu.add(new Option(t[i].getAttribute("name"),t[i].getAttribute("id"))); } } ----------------------------------------------------------- <script runat="server"> void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/XML"; Response.Write("<menus>"); Response.Write("<menu name=\"\" id=\"\" </menu>"); DataTable dt =new DataTable(); dt = (數據 集); foreach(DataRow dr in dt.Rows) { Response.Write("<menu name=\""+dr["name"].ToString()+"\" id=\""+dr["id"].ToString()+"\" </menu>"); } Response.Write("</menus>"; } </script>