html页面
<form id="form1" runat="server">
<div>
<p>评论:</p>
<p>姓名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox> </p>
<p>内容: <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine"></asp:TextBox> </p>
<p>
<%--<asp:Button ID="Button1" runat="server" Text="提 交" />--%>
<input id="Button1" type="button" value="提 交" />
</p> <div class='comment'>已有评论:</div>
<div id="resText" >
</div>
</div>
</form>js文件:$(function() {
//html格式返回数据
// $("#Button1").click(function() {
// $.post("Test6.ashx", {
// username: $("#txtName").val(),
// content: $("#txtContent").val()
// }, function(data, textStatus) {
// $("#resText").html(data); //把返回的数据添加到页面
// });
// })
//xml格式返回数据
// $("#Button1").click(function() {
// $.post("Test6.ashx", {
// username: $("#txtName").val(),
// content: $("#txtContent").val()
// }, function(data, status) {
// var username = $(data).find("comment").attr("username");
// var content = $(data).find("comment content").text();
// var txtHtml = "<div class='comment'><h6>" + username + ":</h6><p class='para'>" + content + "</p></div>";
// $("#resText").html(txtHtml);
// }, "xml");
// })
//json格式返回
$("#Button1").click(function() {
$.post("Test6.ashx", {
username: $("#txtName").val(),
content: $("#txtContent").val()
}, function(data, status) {
var username = data.username;
var content = data.content;
var txtHtml = "<div class='comment'><h6>" + username + ":</h6><p class='para'>" + content + "</p></div>";
$("#resText").html(txtHtml);
}, "json");
})
})//后台是用的ashx来取数据 //json格式返回
try
{
context.Response.ContentType = "text/plain";
string username = context.Request.Params["username"];
string content = context.Request.Params["content"];
context.Response.Write("{username:'" + username + "',content:'" + content + "'}");
}
catch (Exception ex) {
context.Response.Write("{username:'"+ex.Message+"',content:'"+ex.Message+"'}");
}
}
<form id="form1" runat="server">
<div>
<p>评论:</p>
<p>姓名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox> </p>
<p>内容: <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine"></asp:TextBox> </p>
<p>
<%--<asp:Button ID="Button1" runat="server" Text="提 交" />--%>
<input id="Button1" type="button" value="提 交" />
</p> <div class='comment'>已有评论:</div>
<div id="resText" >
</div>
</div>
</form>js文件:$(function() {
//html格式返回数据
// $("#Button1").click(function() {
// $.post("Test6.ashx", {
// username: $("#txtName").val(),
// content: $("#txtContent").val()
// }, function(data, textStatus) {
// $("#resText").html(data); //把返回的数据添加到页面
// });
// })
//xml格式返回数据
// $("#Button1").click(function() {
// $.post("Test6.ashx", {
// username: $("#txtName").val(),
// content: $("#txtContent").val()
// }, function(data, status) {
// var username = $(data).find("comment").attr("username");
// var content = $(data).find("comment content").text();
// var txtHtml = "<div class='comment'><h6>" + username + ":</h6><p class='para'>" + content + "</p></div>";
// $("#resText").html(txtHtml);
// }, "xml");
// })
//json格式返回
$("#Button1").click(function() {
$.post("Test6.ashx", {
username: $("#txtName").val(),
content: $("#txtContent").val()
}, function(data, status) {
var username = data.username;
var content = data.content;
var txtHtml = "<div class='comment'><h6>" + username + ":</h6><p class='para'>" + content + "</p></div>";
$("#resText").html(txtHtml);
}, "json");
})
})//后台是用的ashx来取数据 //json格式返回
try
{
context.Response.ContentType = "text/plain";
string username = context.Request.Params["username"];
string content = context.Request.Params["content"];
context.Response.Write("{username:'" + username + "',content:'" + content + "'}");
}
catch (Exception ex) {
context.Response.Write("{username:'"+ex.Message+"',content:'"+ex.Message+"'}");
}
}
context.Response.Write(s);
Response.Clear();
context.Response.Write("要打印的数据");
Response.End();
试试看