用AJAX前台获取后台.cs数值

用AJAX前台获取后台.cs数值
aspx:
function select (price)
{
      var param = "option=select&price=" + price;
      var options =
      {
                 method: 'post', parameters: param, onComplete:
                 function(transport) {
                     var retv = transport.responseText; //获取到得值
                 }
      }
      new Ajax.Request('index.aspx', options);    // index.aspx 为当前页面
}
.cs
if(Request.Form["option"] != null && Request.Form["option"].Trim().Equals("select"))
{
     Response.Write(...);   //通过Response将数据传给.aspx页面
     Response.End();
     return;
}
以上代码的原理为 1 .aspx页面写好AJAX方法来获取后台数据 2 .cs文件获取页面要显示的数据 通过AJAX的Response.Write()方法传给前台页面
以下为项目部分源码
if (Request.Form["Option"] != null && Request.Form["Option"].Trim().Equals("select"))
                {
                    string where = string.Empty;
                    string prices = Request.Form["price"].ToString().Trim();
                    string[] price = prices.Split('-');
                    if (prices=="0")
                    {
                        where = "";
                    }
                    else if (price.Length>1)
                    {
                        where = " and price between " + price[0] + " and " + price[1]+" ";
                    }
                    else
                    {
                        where = " and price > 5000 ";
                    }
                    StringBuilder sb = BindProductBySearch(where);    //StringBuilder sb来接收下面方法的返回值
                    Response.Write(sb.ToString());   //将sb传给前台页面
                    Response.End();
                    return;
                }
private StringBuilder BindProductBySearch(string strwhere)
        {
            BLL.Shop.ShopProduct shopbll = new BLL.Shop.ShopProduct();
            SqlDataReader reader = shopbll.GetProductForIndex(strwhere);
            StringBuilder products = new StringBuilder();
           
            string style = " style=\"margin-left:0\" ";
            int count = 1;
            while (reader.Read())
            {
                string imageUrl = reader["images"].ToString().Trim();
                string ppxh = reader["PPXH"].ToString().Trim();//品牌
                string price = Convert.ToInt32(reader["Price"]).ToString();
                string model = reader["Model"].ToString();
                string id = Convert.ToInt32(reader["id"]).ToString();
                string pm = TelRen.Common.PubUtil.SubStringTen(ppxh + " " + model, 10);
                string condition = reader["condition"].ToString();
                products.Append("<div class=\"main_pro_box\" ");
                if(count%6==1)
                {
                    products.Append(style);
                }
                products.Append(">\n");
                products.Append("<a href=\"membercenter/pro_show_" + id + "_1.html\"><img src=\"" + imageUrl + "\" width=\"102px\" height=\"102px\" /></a>\n");
                products.Append("<br /><b style=\"color:#FF3300\"><b style=\"color:#666666\">¥</b>" + price + "</b><br />\n");
                products.Append("<span style=\"color:#0045DF\">"+pm+"<br />\n");
                products.Append("成色:"+condition+"</span></div>\n");
                count++;
            }
            reader.Close();
            reader.Dispose();
            reader = null;
            return products;
        }用AJAX前台获取后台.cs数值
用AJAX前台获取后台.cs数值
aspx:
function select (price)
{
      var param = "option=select&price=" + price;
      var options =
      {
                 method: 'post', parameters: param, onComplete:
                 function(transport) {
                     var retv = transport.responseText; //获取到得值
                 }
      }
      new Ajax.Request('index.aspx', options);    // index.aspx 为当前页面
}
.cs
if(Request.Form["option"] != null && Request.Form["option"].Trim().Equals("select"))
{
     Response.Write(...);   //通过Response将数据传给.aspx页面
     Response.End();
     return;
}
以上代码的原理为 1 .aspx页面写好AJAX方法来获取后台数据 2 .cs文件获取页面要显示的数据 通过AJAX的Response.Write()方法传给前台页面
以下为项目部分源码
if (Request.Form["Option"] != null && Request.Form["Option"].Trim().Equals("select"))
                {
                    string where = string.Empty;
                    string prices = Request.Form["price"].ToString().Trim();
                    string[] price = prices.Split('-');
                    if (prices=="0")
                    {
                        where = "";
                    }
                    else if (price.Length>1)
                    {
                        where = " and price between " + price[0] + " and " + price[1]+" ";
                    }
                    else
                    {
                        where = " and price > 5000 ";
                    }
                    StringBuilder sb = BindProductBySearch(where);    //StringBuilder sb来接收下面方法的返回值
                    Response.Write(sb.ToString());   //将sb传给前台页面
                    Response.End();
                    return;
                }
private StringBuilder BindProductBySearch(string strwhere)
        {
            BLL.Shop.ShopProduct shopbll = new BLL.Shop.ShopProduct();
            SqlDataReader reader = shopbll.GetProductForIndex(strwhere);
            StringBuilder products = new StringBuilder();
           
            string style = " style=\"margin-left:0\" ";
            int count = 1;
            while (reader.Read())
            {
                string imageUrl = reader["images"].ToString().Trim();
                string ppxh = reader["PPXH"].ToString().Trim();//品牌
                string price = Convert.ToInt32(reader["Price"]).ToString();
                string model = reader["Model"].ToString();
                string id = Convert.ToInt32(reader["id"]).ToString();
                string pm = TelRen.Common.PubUtil.SubStringTen(ppxh + " " + model, 10);
                string condition = reader["condition"].ToString();
                products.Append("<div class=\"main_pro_box\" ");
                if(count%6==1)
                {
                    products.Append(style);
                }
                products.Append(">\n");
                products.Append("<a href=\"membercenter/pro_show_" + id + "_1.html\"><img src=\"" + imageUrl + "\" width=\"102px\" height=\"102px\" /></a>\n");
                products.Append("<br /><b style=\"color:#FF3300\"><b style=\"color:#666666\">¥</b>" + price + "</b><br />\n");
                products.Append("<span style=\"color:#0045DF\">"+pm+"<br />\n");
                products.Append("成色:"+condition+"</span></div>\n");
                count++;
            }
            reader.Close();
            reader.Dispose();
            reader = null;
            return products;
        }用AJAX前台获取后台.cs数值
用AJAX前台获取后台.cs数值
aspx:
function select (price)
{
      var param = "option=select&price=" + price;
      var options =
      {
                 method: 'post', parameters: param, onComplete:
                 function(transport) {
                     var retv = transport.responseText; //获取到得值
                 }
      }
      new Ajax.Request('index.aspx', options);    // index.aspx 为当前页面
}
.cs
if(Request.Form["option"] != null && Request.Form["option"].Trim().Equals("select"))
{
     Response.Write(...);   //通过Response将数据传给.aspx页面
     Response.End();
     return;
}
以上代码的原理为 1 .aspx页面写好AJAX方法来获取后台数据 2 .cs文件获取页面要显示的数据 通过AJAX的Response.Write()方法传给前台页面
以下为项目部分源码
if (Request.Form["Option"] != null && Request.Form["Option"].Trim().Equals("select"))
                {
                    string where = string.Empty;
                    string prices = Request.Form["price"].ToString().Trim();
                    string[] price = prices.Split('-');
                    if (prices=="0")
                    {
                        where = "";
                    }
                    else if (price.Length>1)
                    {
                        where = " and price between " + price[0] + " and " + price[1]+" ";
                    }
                    else
                    {
                        where = " and price > 5000 ";
                    }
                    StringBuilder sb = BindProductBySearch(where);    //StringBuilder sb来接收下面方法的返回值
                    Response.Write(sb.ToString());   //将sb传给前台页面
                    Response.End();
                    return;
                }
private StringBuilder BindProductBySearch(string strwhere)
        {
            BLL.Shop.ShopProduct shopbll = new BLL.Shop.ShopProduct();
            SqlDataReader reader = shopbll.GetProductForIndex(strwhere);
            StringBuilder products = new StringBuilder();
           
            string style = " style=\"margin-left:0\" ";
            int count = 1;
            while (reader.Read())
            {
                string imageUrl = reader["images"].ToString().Trim();
                string ppxh = reader["PPXH"].ToString().Trim();//品牌
                string price = Convert.ToInt32(reader["Price"]).ToString();
                string model = reader["Model"].ToString();
                string id = Convert.ToInt32(reader["id"]).ToString();
                string pm = TelRen.Common.PubUtil.SubStringTen(ppxh + " " + model, 10);
                string condition = reader["condition"].ToString();
                products.Append("<div class=\"main_pro_box\" ");
                if(count%6==1)
                {
                    products.Append(style);
                }
                products.Append(">\n");
                products.Append("<a href=\"membercenter/pro_show_" + id + "_1.html\"><img src=\"" + imageUrl + "\" width=\"102px\" height=\"102px\" /></a>\n");
                products.Append("<br /><b style=\"color:#FF3300\"><b style=\"color:#666666\">¥</b>" + price + "</b><br />\n");
                products.Append("<span style=\"color:#0045DF\">"+pm+"<br />\n");
                products.Append("成色:"+condition+"</span></div>\n");
                count++;
            }
            reader.Close();
            reader.Dispose();
            reader = null;
            return products;
        }用AJAX前台获取后台.cs数值
用AJAX前台获取后台.cs数值
aspx:
function select (price)
{
      var param = "option=select&price=" + price;
      var options =
      {
                 method: 'post', parameters: param, onComplete:
                 function(transport) {
                     var retv = transport.responseText; //获取到得值
                 }
      }
      new Ajax.Request('index.aspx', options);    // index.aspx 为当前页面
}
.cs
if(Request.Form["option"] != null && Request.Form["option"].Trim().Equals("select"))
{
     Response.Write(...);   //通过Response将数据传给.aspx页面
     Response.End();
     return;
}
以上代码的原理为 1 .aspx页面写好AJAX方法来获取后台数据 2 .cs文件获取页面要显示的数据 通过AJAX的Response.Write()方法传给前台页面
以下为项目部分源码
if (Request.Form["Option"] != null && Request.Form["Option"].Trim().Equals("select"))
                {
                    string where = string.Empty;
                    string prices = Request.Form["price"].ToString().Trim();
                    string[] price = prices.Split('-');
                    if (prices=="0")
                    {
                        where = "";
                    }
                    else if (price.Length>1)
                    {
                        where = " and price between " + price[0] + " and " + price[1]+" ";
                    }
                    else
                    {
                        where = " and price > 5000 ";
                    }
                    StringBuilder sb = BindProductBySearch(where);    //StringBuilder sb来接收下面方法的返回值
                    Response.Write(sb.ToString());   //将sb传给前台页面
                    Response.End();
                    return;
                }
private StringBuilder BindProductBySearch(string strwhere)
        {
            BLL.Shop.ShopProduct shopbll = new BLL.Shop.ShopProduct();
            SqlDataReader reader = shopbll.GetProductForIndex(strwhere);
            StringBuilder products = new StringBuilder();
           
            string style = " style=\"margin-left:0\" ";
            int count = 1;
            while (reader.Read())
            {
                string imageUrl = reader["images"].ToString().Trim();
                string ppxh = reader["PPXH"].ToString().Trim();//品牌
                string price = Convert.ToInt32(reader["Price"]).ToString();
                string model = reader["Model"].ToString();
                string id = Convert.ToInt32(reader["id"]).ToString();
                string pm = TelRen.Common.PubUtil.SubStringTen(ppxh + " " + model, 10);
                string condition = reader["condition"].ToString();
                products.Append("<div class=\"main_pro_box\" ");
                if(count%6==1)
                {
                    products.Append(style);
                }
                products.Append(">\n");
                products.Append("<a href=\"membercenter/pro_show_" + id + "_1.html\"><img src=\"" + imageUrl + "\" width=\"102px\" height=\"102px\" /></a>\n");
                products.Append("<br /><b style=\"color:#FF3300\"><b style=\"color:#666666\">¥</b>" + price + "</b><br />\n");
                products.Append("<span style=\"color:#0045DF\">"+pm+"<br />\n");
                products.Append("成色:"+condition+"</span></div>\n");
                count++;
            }
            reader.Close();
            reader.Dispose();
            reader = null;
            return products;
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值