首页 > 代码库 > .NET 一般处理程序完成AJAX操作
.NET 一般处理程序完成AJAX操作
jQuery("#btn").click(function () {
var commentMessahe = jQuery("#CommentNote").val();
var num = jQuery("#CommentNote").val().length;
if (username != "") {
if (commentMessahe != "") {
if (falgText) {
if (isvalidatecode) {
jQuery.ajax({
type: "Post",
url: "http://www.taogujie.com/Handler/JDCommentlHander.ashx?jd=AddComment",
data: { AppraisalID: appraisalID, CommentNote: commentMessahe },
success: function (data) {
if (data.isok) {
if (data.result == 1) {
alert("评论成功");
jQuery("#message").val("");
window.location.href = "http://www.mamicode.com/jd-" + appraisalID + ".html";
}
else {
alert("评论失败");
}
}
}, error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("错误");
},
});
}
}
}
}
});
C#
public override object ProcessRequest()
{
if (action == "AddComment")
{
//获取登录用户
WBMall.Business.SSO.UserCookiesService userCookieService = new WBMall.Business.SSO.UserCookiesService();
ResultInfo<WBMall.Model.Common.SmallUserInfo> results = userCookieService.CheckLogin();
string uName = "";
string uId = "";
if (results.Result)
{
uName = results.Data.Account;
uId = results.Data.Code;
}
string commentNote = HttpPageHelper.RequestString("CommentNote");
int appraisalID = HttpPageHelper.RequestInt("AppraisalID");
AppraisalCommentModel model = new AppraisalCommentModel();
model.AppraisalID = appraisalID;
model.CommentNote = commentNote;
model.IP = WBMall.PMethod.Users.GetIP();
model.CreateTime = DateTime.Now;
model.ComUserID =int.Parse(uId.ToString());
model.ComUserName = uName.ToString();
model.IsDelete = false;
model.IsShow = false;
model.AdminID = 1;
var result = jdbll.AddAppraisalComment(model);
if (result.Result)
{
if (result.Data) { return 1; } else { return 0; }
}
}
else if (action == "checkvalidate")
{
if (CheckValidateCode()) { return 1; } else { return 0; }
}
else if (action == "checklogin")
{
return CheckLogin();//检查是否登录并且返回用户名
}
return null;
}
.NET 一般处理程序完成AJAX操作