Jquery读取Handler.ashx文件
Jquery处理一般文件和大家分享一下
http://s.click.taobao.com/t_8?e=7HZ5x%2BOzdswsVvyc5Jts79Au1Q%3D%3D&p=mm_24156262_0_0
function clickfun() {
try {
var auctionIndx = $("#HiddenField1").val();
//插入数据返回读取结果
$.get("InsertTauctionInfo.ashx?dateid=" + new Date(), { "auctionId": auctionIndx, "phone": $("#txtPhone").val(), "bidPrice": $("#txtBidPrice").val() }, function(data) {
alert(data);
});
} catch (e) {
location.reload();
}
}
C# Code InsertTauctionInfo.ashx
<%@ WebHandler Language="C#" class="InsertTauctionInfo" %>
using System;
using System.Web;
using System.Data;
public class InsertTauctionInfo : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//获取请求的数据
string auctionId = HttpContext.Current.Request.QueryString["AuctionId"];
string bidPrice = HttpContext.Current.Request.QueryString["BidPrice"];
string phone = HttpContext.Current.Request.QueryString["phone"];
context.Response.Write(BidPriceMethod(auctionId, phone, bidPrice));
}
public bool IsReusable
{
get
{
return false;
}
}
public string BidPriceMethod(string auctionId, string phone, string bidPrice)
{
string returnvalue = "";
try
{
if (auctionId != null)
{
string consigneeMobi = @"^(13|15|18)[0-9]{9}$";// @"^(1[0-9])\d{9}$";
string cellphone = "";
if (System.Text.RegularExpressions.Regex.IsMatch(phone, consigneeMobi)) //手机号码
{
cellphone = phone;
}
else
{
returnvalue = "手机号码格式不正确 如:13888888888";
return returnvalue;
}
if (string.IsNullOrEmpty(bidPrice))
{
returnvalue = "请输入自定义价格";
return returnvalue;
}
DataTable tableName = BLL.TAuctionBidBLL.SelectAuctionInfoMaxUser(auctionId);
if (tableName != null && tableName.Rows.Count > 0)
{
if (tableName.Rows[0][0].ToString() == usName)
{
returnvalue = "不能连续出价";
return returnvalue;
}
}
try
{
Int64 maxBidPrice = BLL.TAuctionBidBLL.SelectTauctionBidWithMaxBidPrice(Convert.ToInt32(auctionId)); //查询出当前竞拍中最高出价
BidPrice = Convert.ToInt64(bidPrice);//传入过来的出价值
Int64 maxAddPrice = (Int64)BLL.TauctionInfoBLL.maxAddPrice(auctionId);//查询出最高加价
DataTable priceTable = BLL.TauctionInfoBLL.GetEndPrice(auctionId);
Int64 strPrice = Convert.ToInt64(priceTable.Rows[0][0]);
Int64 endPrice = Convert.ToInt64(priceTable.Rows[0][1]);
if (BidPrice < strPrice)
{
returnvalue = "您出价不能小于起始价,请重新出价";
return returnvalue;
}
if (maxBidPrice == 0)
{
Int64 isMaxStrPrice = BidPrice - strPrice;
if (isMaxStrPrice > maxAddPrice)
{
returnvalue = "您出价过高,每次加价最多能加价" + maxAddPrice + "元";
return returnvalue;
}
}
else
{
Int64 isMaxprice = BidPrice - maxBidPrice;
if (isMaxprice > maxAddPrice)
{
returnvalue = "您出价过高,每次加价最多能加价" + maxAddPrice + "元";
return returnvalue;
}
}
if (BidPrice <= maxBidPrice)
{
returnvalue = "您出价过低,请重新出价";
return returnvalue;
}
if (BidPrice > endPrice)
{
returnvalue = "您出价过高,以免造成损失,请重新出价 ";
return returnvalue;
}
}
catch
{
returnvalue = " 请输入正确的价格,价格必须是整数,如:100 ";
return returnvalue;
}
System.Web.HttpContext.Current.Application.Lock();
Model.TAuctionBid auctionBid = new Model.TAuctionBid();
auctionBid.Auction_id = Convert.ToInt32(auctionId);
auctionBid.User_id = usName;
auctionBid.Bidprice = Convert.ToInt32(BidPrice);
auctionBid.Createdate = DateTime.Now;
int inserBid = BLL.TAuctionBidBLL.InsertTAuctionBid(auctionBid);
System.Web.HttpContext.Current.Application.UnLock();
if (inserBid > 0)
{
BLL.TauctionInfoBLL.UpdateUserPhone(auctionBid.User_id, cellphone);
returnvalue = "恭喜您出价成功";
return returnvalue;
}
else
{
//转跳到错误页面
returnvalue = "出价失败";
return returnvalue;
}
}
}
catch
{
returnvalue = "出价失败";
return returnvalue;
}
return returnvalue;
}
}
http://s.click.taobao.com/t_8?e=7HZ5x%2BOzdswsVvyc5Jts79Au1Q%3D%3D&p=mm_24156262_0_0