소프트웨어/C# & ASP.NET

ASP.NET AJAX 와 jquery 의 함께 사용하기 #2

falconer 2009. 5. 19. 11:31
DataSet 을 PageMethod에서 JSON 개체로 반환한다.
01.function Button1_Click() {
02.    $.ajax({
03.        type: "POST",
04.        url: "TestPageMethodDataSet.aspx/PageMethodDataSet",
05.        data: "{}",
06.        contentType: "application/json; charset=utf-8",
07.        dataType: "json",
08.        success: function(response) { 
09.        // response.d.length // Row Count
10.        // response.d[0].code
11.        // response.d[0].codeName
12.        // response.d[1].code
13.        // response.d[1].codeName
14.            ...
15.        }
16.    });   
17.}
01.[WebMethod]
02.public static IEnumerable PageMethodDataSet()
03.{
04.    CodeManager blc = new CodeManager();
05.    DataSet ds = blc.SelectCode();
06.    XDocument xdata = XDocument.Parse(ds.GetXml());
07.    return // var xquery =
08.        from item in xdata.Descendants("Table")
09.        select new
10.        {
11.            code = item.Element("CODE").Value,
12.            codeName = item.Element("CODE_NAME").Value
13.        };
14.}


출처 : http://fivewind.tistory.com/207