• Ajax--WebService返回List


    WebService:

        using System.Web.Script.Services;
        [GenerateScriptType(typeof(people))]
    
        [WebMethod]
        public List<people> GetPeopleList()
        {
            List<people> list = new List<people>();
            for (int i = 0; i < 10; i++)
            {
                people p = new people();
                p.Name = "我是" + i.ToString();
                list.Add(p);
            }
    
            return list;
        }

    ScriptManager:

        <asp:ScriptManager ID="sm" runat="server">
        <Services>
            <asp:ServiceReference Path="~/WebService2.asmx" InlineScript="true" />
        </Services>
        </asp:ScriptManager>

    页面控件:

        <input type="button" value="添加" onclick="btn_click()" id="btn" />
        <div id="result">
        
        </div>

    Js:

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

    结果:

    image

    debugger:

    image

  • 相关阅读:
    PowerGhost
    watchdogs感染性挖矿病毒
    XorDDoS木马
    Gates(盖茨)木马
    seasame病毒
    zabbix监控之邮件报警通知
    ubuntu18.04 heirloom-mailx 通过外部SMTP服务器发送邮件
    linux小常识
    zabbix基本概念
    Zabbix图表中文乱码
  • 原文地址:https://www.cnblogs.com/loveYN/p/4509620.html
Copyright © 2020-2023  润新知