Json+jquery+asp.netはデータベースのデータを返します.

17212 ワード

フロント:
 


コード

   
     
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head id = " Head1 " runat = " server " >
< title ></ title >
<%--< script src = " js/jquery-1.3.2.js " type = " text/javascript " ></ script >--%>
< script src = " js/jquery.js " type = " text/javascript " ></ script >
< script type = " text/javascript " language = " javascript " >
$(document).ready(function() {
$(
" #btn " ).click(function() {
$.getJSON(
" show.ashx " , // JSON
function(json) {
// json ,
$.each(json, function(i) {
$(
" #list " ).append( " <li>username: " + json[i].FuserName + " &nbsp; userPWD: " + json[i].FpassWord + " &nbsp; Fmail: " + json[i].Fmail + " &nbsp; Fadress: " + json[i].Fadress + " </li> " )
})
});
})
});
</ script >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
< h3 title = " " >< span > </ span ></ h3 >
< input id = " btn " type = " button " value = " " />

< ul id = " list " ></ ul >
</ div >
</ form >
</ body >
</ html >
 
バックグラウンド:


コード

   
     
<% @ WebHandler Language = " C# " Class = " show " %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Web.Script.Serialization; //
using DAL;
using model;

public class show : IHttpHandler {

public void ProcessRequest (HttpContext context) {
JavaScriptSerializer serializer
= new JavaScriptSerializer();
IList
< Tuser > tuser = UserDB.getList();
string dt = serializer.Serialize(tuser);
context.Response.ContentType
= " text/plain " ;
context.Response.Write(dt);
}

public bool IsReusable {
get {
return false ;
}
}

}