Ajax--WebService返回ArrayList

it2024-11-13  14

前: debugger后,和数组很像

 

自定义类:

public class people { private string name; public string Name { get { return name; } set { name = value; } } private string password; public string Password { get { return password; } set { password = value; } } }

 

WebService:

[WebMethod] public ArrayList GetArrayList() { ArrayList al = new ArrayList(); for (int i = 0; i < 10; i++) { people p = new people(); p.Name = "Name:" + i.ToString(); al.Add(p); } return al; }   ScriptManager: <asp:ScriptManager ID="sm" runat="server"> <Services> <asp:ServiceReference Path="~/WebService2.asmx" /> </Services> </asp:ScriptManager>   页面控件: <input type="button" value="Click Me!" οnclick="btn_click()" id="btn" /> <select id="st"> </select>

 

Js:

<script type="text/javascript"> function btn_click(){ WebService2.GetArrayList(onSuccessed); } function onSuccessed(result){debugger; for(var i=0;i<result.length;i++){ var label = document.createElement("label"); label.innerHTML=result[i]["Name"]+"<br/>"; $get("result").appendChild(label); } } </script>  

debugger后:

 

效果:

转载于:https://www.cnblogs.com/oneword/archive/2009/05/05/1449307.html

最新回复(0)