一、WebService.asmx:
处理业务数据,在GetList方法中产生泛型集合数据,供JqueryRequest.aspx调用,代码如下:
[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>