积极答复者
点击一个button,页面无跳转生成一个table,这个该怎么做

问题
答案
-
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript">
var xmlHttp;
function showCustomer() {
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
alert("您的浏览器不支持AJAX!");
return;
}
var url = "ajaxd.ashx";
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChanged() {
if (xmlHttp.readyState == 4) {
document.getElementById("sessiontext").innerHTML = xmlHttp.responseText;
}
}
function GetXmlHttpObject() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<span id="sessiontext">
</span>
<input id="Button1" onclick="showCustomer()" type="button" value="清除session" />
</div>
</form>
</body>
</html>
我用的js异步的页面是ASHX 中文叫一般处理程序 你可以用aspx替代
我这个页面取名叫ajaxd.ashx只有后台代码using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace WebApplication1 { /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class ajaxd : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write(" <table>
<tr>
<td>11</td>
</tr>
<tr>
<td>22</td></tr>
</table>"); context.Response.End(); } public bool IsReusable { get { return false; } } } }- 已标记为答案 炫速飞火 2009年10月18日 4:43
全部回复
-
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript">
var xmlHttp;
function showCustomer() {
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
alert("您的浏览器不支持AJAX!");
return;
}
var url = "ajaxd.ashx";
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChanged() {
if (xmlHttp.readyState == 4) {
document.getElementById("sessiontext").innerHTML = xmlHttp.responseText;
}
}
function GetXmlHttpObject() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<span id="sessiontext">
</span>
<input id="Button1" onclick="showCustomer()" type="button" value="清除session" />
</div>
</form>
</body>
</html>
我用的js异步的页面是ASHX 中文叫一般处理程序 你可以用aspx替代
我这个页面取名叫ajaxd.ashx只有后台代码using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace WebApplication1 { /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class ajaxd : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write(" <table>
<tr>
<td>11</td>
</tr>
<tr>
<td>22</td></tr>
</table>"); context.Response.End(); } public bool IsReusable { get { return false; } } } }- 已标记为答案 炫速飞火 2009年10月18日 4:43