zoukankan      html  css  js  c++  java
  • asp.net 使用Jquery 调用WebService返回JSON 类型数据

    webservice定义方法如下

           [WebMethod]
            public List<Temp> GetTest()
            {
                List<Temp> test = new List<Temp>();
                test.Add(new Temp() { PersonCode="111", PersonName="222", Progress=2, Sex="2", test="test"});
                test.Add(new Temp(){ PersonCode="333", PersonName="444", Progress=2, Sex="2", test="test"});
                return test;
            }

    Temp为公共访问的实体类.

    客户端Jquery代码如下:

            /*
                1、WebService请求类型都为Post,WebService的Url为“[WebServiceUrl]/[WebMethod]”
                2、contentType声明为Json
                3、data要用Json的字符串格式传入
                4、设置了dataType为json后,result就直接为返回的Json对象。
            */

             $.ajax({
                    url: "../Services/PhysicalEnterService.asmx/GetTest",
                    type: "POST",
                    contentType: "application/json",
                    data:{},
                    dataType: "json",
                    success: function(result) {
                        alert(result.d[0].PersonName);
                    },
                    error: function(error) {
                        alert(error.responseText);
                    }
                });

    调用成功后返回json对象.

  • 相关阅读:
    使用kerl安装erlang遇到的问题及解决办法-bak
    zip无法解压
    利用正则表达式统计访问频率
    windows开dump
    ftp禁止切换回上级目录
    windows组策略屏蔽
    对于超体的一点思考
    测试php语句执行时间
    php中点击下载按钮后待下载文件被清空
    mysql_fetch_assoc查询多行数据
  • 原文地址:https://www.cnblogs.com/wuhen/p/1741936.html
Copyright © 2011-2022 走看看