例如我在后台有个   public List<Customer> GetCustomerList(Customer param){}
这样一个方法,我要在前台获取这个方法的list然后循环将数据增充到页面中,
在网上找了下说通过web service 那不是每个方法都要写一个web service ?

解决方案 »

  1.   

    将方法定义成 WebMethod 就可以了
      

  2.   

    前台是不认识你IList 要么你吧这个Ilist弄能json数据格式,Write到前台ajax 要么Webservie他自己是封装成xml它自动弄的.
      

  3.   

    不一定非要写web service的,普通的页面也能实现。
      

  4.   

    @net_lover老大,给您发私信了,不知是否收到
      

  5.   

    我在RecordAskPrice.cs后台有个public List<Customer> GetCustomer(){}
    返回是一个list 然后我在前台一个文本框绑定一个blur事件
     
            $("#TB_type").blur(function(){
              $.ajax({
              type: "POST",
              url: "RecordAskPrice.aspx/GetCustomer",
              data: "{':''}",
              contentType: "application/json; charset=utf-8",
              success: function(msg) 
               {
                alert(msg);
              
               }
              })怎么不对呀
      

  6.   

    我不需要定义webMethod 不想用webservice
      

  7.   

    因为麻烦呀! 我每个方法还定义一个web service 吗 不太好,感觉还是先直接调用的好,但是这里调不出数据来
      

  8.   

    JS:
     
    引用ScriptManage控件JS代码:PageMethods.GetStr(str,function(result){//参数个数可选,逗号分隔
                  //回调函数
                 }
            );CS代码:
    using System.Web.Severs;[WebMethod]
    public static string GetStr(string str)
    {}
      

  9.   

    刚在项目中用过 $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "Menu.aspx/CheckChildMenuName",
                    data: "{ParentID:'" + MenuID + "',ProjectID:'<%=this.SortProjectID %>'}",
                    dataType: 'json',
                    async: false,      //ajax同步
                    success: function(result) {
                        temp = result.d;
                    }
                });CheckChildMenuName代表后台 方法ParentID,ProjectID后台方法参数[WebMethod]
    [ScriptService]
        public .....: Eson.UMS.Common.UmsBasePage
        {
            public static string CheckChildMenuName(string ParentID, string ProjectID)
            {}
    }
      

  10.   

    你的问题是想用 ajax 来访问 服务器端的方法ajax 与 普通的 http 请求的区别是 异步的它需要你提供服务器端可供客户端访问的资源,eg: .aspx 、 .ashx  or webmethod
      

  11.   

            $(document).ready(function (){
              $("#TB_content").blur(function(){
                 $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "Default.aspx?fname=GetInfo",
                    data:"{':'}",
                    dataType: 'json',
                    async: true,     
                    success: function(result) {
                    alert(result);
                  }
                });
                 });
          });  // 
    这句明明已经有了 GetInfo 里面的值了,但是 alert不出来呀 我应该怎么获取这个值呀
      

  12.   

    Default.aspx?fname=GetInfo之后做了什么
      

  13.   

    http://topic.csdn.net/u/20100312/14/6A9AC687-A120-4F0B-B94F-A685C9343A76.html
      

  14.   

    Sandy945 谢谢你一直支持我,我先去看看你发的这个链接,然后再试试看, 非常谢谢, 成功了结贴多加点分报答你..
      

  15.   


    <script type="text/javascript">
            $(function() {
                $.ajax({
                    url: "xxx.aspx",
                    dataType: "json",
                    type: "GET",
                    error: function() {
                        alert("ERROR");
                    },
                    success: function(data) {
                          showDom(data);
                    }
                }); 
            });        var showDom = function(obj) {
                $("#DivTable").find("tbody:last").find("tr").remove();
                var domStr = "";
                $.each(obj.ListInfo, function(i, v) {
                    domStr += "<tr><td>" + v.ID + "</td><td>" + v.Name + "</td><td>" + v.Sex + "</td></tr>";
                });
                
                $("#DivTable").find("tbody:last").append(domStr);
               
            }
        </script><body>
        <form id="form1" runat="server">
        <div>
        <table id="DivTable" class="table">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>姓名</th>
                    <th>性别</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
        </div>
        
        </form>
        
    </body>
    xxx.aspx:String str = "{ListInfo:[";
    for (Customer one in listin)
    {
       str += "{ID:\""+one.Id.ToString()+"\",Name:\""+one.Name.ToString()+"\",Sex:\""+one.Sex.ToString()+"\",";
    }
    str = str.Substring(0, str.Length - 1) + "]}";
    Response.Write(str);
    Response.Flush();
      

  16.   

    itliyi  可以获取到后台的数据是对的,现在就是你那个追加到页面的代码有问题能改下吗? 运行的时候会执行 error: function() {
                        alert("ERROR");
                    },
      

  17.   

    应该没错啊
    那xxx.aspx 用Handler.ashx试试
      

  18.   

    sandy945 Very Handsome  專家  大好人
      

  19.   

    itliyi 你QQ是多少呀 加下你行吗? 我的是 396464010 麻烦了
      

  20.   

    用我同事的话说,用啊炸死他(ajax)