JQuery调用WebServices的方法和4个实例

2020-05-17 06:25:04易采站长站整理

                    success: function(json) { alert(json.d); },
                    error: function(error) {
                        alert(“调用出错” + error.responseText);
                    }
                });
            });


后端WebMethod:

[WebMethod]
        public List<Student> GetStudentList(Student stu)
        {
            List<Student> studentList = new List<Student>
            {
                new Student{ID=1,Name=”张三”},
                new Student{ID=2,Name=”李四”}
            };
            //把从客户端传来的实体放回到返回值中
            studentList.Add(stu);
            return studentList;
        }
用谷歌调试的结果:



四、返回匿名对象的WebMethod的调用
前端JS代码:

$(“#btn4”).click(function() {
                $.ajax({
                    type: “POST”,
                    contentType: “application/json; charset=utf-8”,
                    url: “CalledByJquery.asmx/ReturnNoNameClass”,
                    data: “{}”,
                    dataType: “json”,