时间:2021-07-01 10:21:17 帮助过:23人阅读
[WebMethod]
代码如下:
public List<string> GetList()
{
List<string> list = new List<string>();
list.Add("aaaaaaaaaaaa");
list.Add("bbbbbbbbbbbb");
list.Add("cccccccccccc");
list.Add("dddddddddddd");
return list;
}
二、AjaxRequest.aspx
通过点击按钮来请求WebService.asmx的 GetList()方法,获取泛型集合。代码如下:
代码如下:
<script type="text/javascript" language="javascript">
function BtnList_Click() {
$.ajax({
url: "aa.asmx/GetList",
data: {},
type: "post",
success: function(data, status) {
var str = "";
try {
var obj = $(data.xml);
var vals = obj.find("string");
$.each(vals, function(index, item) {
str += $(item).text() + "<br/>";
});
$("#dd").html(str);
}
catch (ex) {
alert(ex);
}
}
});
}
</script>