<script type="text/javascript">
$(function() {
$("#btn").click(function() {
var msg = $("textarea[rows=10]").val();
$.post("pinglun.ashx", { "message": $("textarea[rows=10]").val() }, function(data, status) {
if (status != "success") {
alert("评论失败");
return;
}
var arr = data.split("|");
if (arr[0] == "ok") {
var new_pinglun = $("<tr><td>" + arr[1] + "</td><td>" + arr[2] + "</td><td>" + arr[3] + "</td></tr>");
$("table:first").append(new_pinglun);
alert("评论成功");
}
else {
alert("评论有问题");
}
});
});
});
</script>
<table>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
<HeaderTemplate><tr><td>评论人</td><td>内容</td><td>时间</td></tr></HeaderTemplate>
<ItemTemplate><tr><td><%#Eval("nick") %></td><td><%#Eval("msg") %></td><td><%#Eval("date") %>></td></tr></ItemTemplate>
</asp:Repeater>
</table>
<textarea rows="10" cols="30"></textarea><br/>
<input type="button" value="评论" id="btn" />
ashx:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string nick = context.Session["nick"].ToString();
if (nick == null)
{
nick = context.Request.UserHostAddress;
}
string msg=context.Request["message"];
new pinglunTableAdapter().Insert(nick,msg,DateTime.Now);
context.Response.Write("ok|" + nick + "|" + msg + "|" + DateTime.Now);
}
就是点完按钮没任何反映,在后台ProcessRequest插入断点根本就运行不到
------解决方案--------------------------------------------------------
$.post("test.aspx", { name: "John", time: "2pm" } ); 这里jquery的标准写法
注意一下,里面的参数name,time是不加引号的