用Repeater绑定数据,点赞功能,老大催着要,也没有太大的访问量暂时没写 数据并发
后台写方法读出点赞数据
开始写jQuery
//jquery基本语法就不细说了
<script type="text/javascript">
$(function(){
$(".img_zan").mouseover(function(){
$(this).children().attr("src","images/t_fwsc/Thumb_mouseover1.png");
});
$(".img_zan").mouseout(function(){
$(this).children().attr("src","images/t_fwsc/s-4.png");
});
$(".img_zan").click(function(){
$(this).children().attr("src","images/t_fwsc/Thumb_up2.png");
// $(".add0").removeClass("add_1");
// $(".add0").addClass("add_piao");
// $(".add0").animate({top:"-100px",opacity:'0'},"slow");
/******************************加一样式开始******************************/
$(this).next().children().children().next(".add0").removeClass("add_1");
$(this).next().children().children().next(".add0").addClass("add_piao");
$(this).next().children().children().next(".add0").animate({top:"-200px",opacity:'0'},"slow");
/******************************加一样式开始******************************/
var _a= parseInt($(this).next().text());//当前点赞数
var b="1";//嘻嘻,命名不规范了,测试用的
var masterId=$("#MasterId").val();//用户Id
var orgId=$(this).siblings("#OrgId").val();//联盟医院Id
//之前接触过Ajax,好久不写前端快忘干净了,看了看Jquery的API ----》》》http://www.w3school.com.cn
$.ajax({
url:"/ashx/MasterPraiseAjax.ashx", //发送请求的地址 Get请求方式
data:{WebName:b,masterId:masterId,OrgId:orgId},//参数 必须以键值对传递 master
async:false,//类型:Boolean 默认值: true。默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。
success:function(data){ //返回值
if(data=="-1")//未登录情况下跳转
{
location.href = "Login.aspx"; //location.href实现客户端页面的跳转
}else if(data=="1"){ //点赞
_a+=1;
//alert(data);
}else if(data=="0"){ //取消点赞
_a-=1;
}else{
_a+=1;
}
}
});
$(this).next().children().text(_a);//给点赞数量重新赋值 (+1or-1)
$(this).removeClass("img_zan").addClass("img0");
$(this).next().removeClass("zanshu").addClass("zanshu0");
});
});
</script>
//下面是一般处理程序
using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.SessionState;
using Common;
using Model.Linq;
namespace Web.ashx
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MasterPraiseAjax : IHttpHandler, IReadOnlySessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//Ajax传递的参数值
string a = context.Request.QueryString["WebName"];
string masterId = context.Request.QueryString["masterId"];
string orgId = context.Request.QueryString["orgId"];
try
{
if (masterId.IsNullOrEmptyOrWhiteSpace())
{
context.Response.Write("-1");
}
else
{
//一下就是点赞状态的操作的 数据量大的话不建议用如下写法,之后会研究一下 并发点赞 偷了懒了
if (!a.IsNullOrEmptyOrWhiteSpace())
{
phDataContext ph = new phDataContext();
PetMasterPraise prais = ph.PetMasterPraise.Where(p=>p.PetMasterId==Convert.ToInt32(masterId)&&p.SourceId==Convert.ToInt32(orgId)&&p.SourceType==2).FirstOrDefault();
//点赞
if (prais == null)
{
PetMasterPraise praise = new PetMasterPraise();
praise.PetMasterId = Convert.ToInt32(masterId);
praise.SourceId = Convert.ToInt32(orgId);
praise.SourceType = 2;
praise.CreateDate = DateTime.Now;
praise.State = 1;
praise.Title = "联盟点赞";
ph.PetMasterPraise.InsertOnSubmit(praise);
ph.SubmitChanges();
context.Response.Write(praise.State);
}
//点赞
else if (prais.State == 0)
{
prais.State = 1;
ph.SubmitChanges();
context.Response.Write(prais.State);
}
else
{
//取消点赞
prais.State = 0;
ph.SubmitChanges();
context.Response.Write(prais.State);
}
}
}
}
catch (Exception ex)
{
LogHelper.WriteLog("联盟点赞异常",ex);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
<div style="height: 30px; width: 150px; float: left; border: 0px;">
<input type="hidden" id='OrgId' value='<%#Eval("Id") %>' />
<div class="img_zan">
<img src="images/t_fwsc/s-4.png" /></div>
<div style="height: 30px; width: 60px; float: left; border: 0px;">
<span class="zan_span"><span class="zanshu"><%# StarCount(Eval("Id"),2) %></span><span class="add_1 add0">+1</span>
</span>
</div>
<input type="hidden" runat="server" id="hidPar" value="" />
<div style="height: 30px; width: 20px; float: left; border: 0px;">
</div>
<div style="height: 30px; line-height: 30px; width: 40px; float: left; border: 0px;">
点赞
</div>
</div>
小白一枚 写的多有不合理的地方会慢慢改进...