asp.net ajax问题
js代码
<script language="javascript" type="text/javascript">
var xmlhttp;
function Validation() {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var uname = document.getElementById("Text1").value;
xmlhttp.open("name", "Ajax1.aspx?uname=" + uname);
xmlhttp.onreadystatechange = OnMessageBack;
xmlhttp.send(null);
}
function OnMessageBack() {
if (xmlhttp.readystate == 4) {
document.write(xmlhttp.responsetext);
}
}
</script>
c#代码
StringBuilder sb = new StringBuilder();
sb.Append("<table border=1><tr><td>编号</td><th>标题</th><th>文件名</th><th>封面</th><th>描述</th><th>源文件</th></tr>");
string sql = "select * from db_doc where did= '"+name+"'";
SqlConnection conn = new SqlConnection("server=.;database=doc;uid=sa;pwd=chang");
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = null;
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
sb.Append("<tr>");
sb.Append("<td>");
sb.Append(reader[0]);
sb.Append("</td>");
sb.Append("<td>");
sb.Append(reader[1]);
sb.Append("</td>");
sb.Append("<td>");
sb.Append(reader[2]);
sb.Append("</td>");
sb.Append("<td>");
sb.Append(reader[3]);
sb.Append("</td>");
sb.Append("<td>");
sb.Append(reader[4]);
sb.Append("</td>");
sb.Append("<td>");
sb.Append(reader[5]);
sb.Append("</td>");
sb.Append("</tr>");
}
sb.Append("</table>");
ViewState["list"] = list;
Response.Write(sb.ToString());
conn.Close();
aspx代码
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="Text1" />
<input type="button" value="登录" onclick="Validation()" />
</div>
<div id="content">
</div>
</form>
</body>
如何把查询返回的结果放到id为content的div中???