jquery 调用后台方法
来源:互联网 发布:金蝶科目初始数据录入 编辑:程序博客网 时间:2024/05/21 17:53
前台页面代码CsdnAddComment.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CsdnAddComment.aspx.cs"
Inherits="Study.CsdnAddComment" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>仿CSDN添加评论</title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnComment").click(function () {
var txtComment = $("#txtComment").val();
$.ajax({
type: "post",
url: "CsdnAddComment.aspx/AddComment",
data: " { 'comment':'" + txtComment + "'}",
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function (message) {
$("#Comment").append('<div class="NewComment">' + txtComment + '</div>');
$("#NewComment").next().slideToggle();
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<center>
<div style="width: 50%">
新闻列表:
<asp:Repeater ID="rpNews" runat="server">
<ItemTemplate>
<div>
<%#DataBinder.Eval(Container.DataItem, "news_title")%>
</div>
<hr />
</ItemTemplate>
</asp:Repeater>
<div id="Comment">
</div>
</div>
<div>
<textarea id="txtComment" rows="8" cols="70"></textarea><br />
<input type="button" value="评论" id="btnComment"/>
</div>
</center>
</form>
</body>
</html>
后台代码CsdnAddComment.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
namespace Study
{
public partial class CsdnAddComment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetNewsList();
}
}
/// <summary>
/// 获取新闻列表
/// </summary>
private void GetNewsList()
{
News n = new News();
List<News> newsList = n.GetNewsList();
rpNews.DataSource = newsList;
rpNews.DataBind();
}
//添加新评论
[WebMethod]
public static string AddComment(string comment)
{
string sqlStr = "insert into tb_news(news_title,news_content,news_time,news_readtimes) values('" + comment + "','内容','2011/6/8','100')";
if (SQLHelper.ExecuteNonQuery(sqlStr) > 0)
{
return "success";
}
else
{
return "failed";
}
}
}
}
- JQuery调用后台方法
- jquery 调用后台方法
- JQuery调用后台方法
- JQuery调用后台方法
- jquery ajax调用后台方法
- jQuery调用页面后台方法
- jQuery Ajax 调用后台方法
- jQuery调用页面后台方法
- jquery ajax调用asp.net 后台方法
- JQuery调用asp.net后台方法
- JQuery Ajax调用asp.net后台方法
- jquery调用asp.net 页面后台方法
- jquery调用asp.net 页面后台方法
- JQuery调用asp.net后台方法
- C# 利用JQuery调用后台方法
- jQuery.ajax()调用asp.net后台方法
- JQuery调用asp.net后台方法
- C# 利用JQuery调用后台方法
- 数据结构读书笔记
- 关于使用log4net.dll记录日志的方法大全
- 在ubuntu下源码编译安装 emacs24
- 向上扩展
- IOS笔试题
- jquery 调用后台方法
- 《C语言参悟之旅》-读书笔记(一)
- JavaScript 注入攻击
- 儿童引导服务 带来安全呵护
- 两条比较实用的mysql导入导出命令
- Linux中Samba详细安装
- 修改root密码passwd: Authentication token manipulation error
- 用友公司Java面试题(含答案)
- 子模的性质(submodular)