首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

求大神来帮忙,做购物车的时候jquery的ajax返回值出有关问题了

2013-01-11 
求大神来帮忙,做购物车的时候jquery的ajax返回值出问题了我大概描述下我要实现的功能,我做购物车,根据产品

求大神来帮忙,做购物车的时候jquery的ajax返回值出问题了
我大概描述下我要实现的功能,我做购物车,根据产品颜色,尺码id获取相对的库存,价格,要实时更新的那种。
我的做法是用ajax发到一个ajax.aspx页面上去做处理,然后返回值,可是这中间返回来的东西完全不是我想要的,大神们看下我错在哪?正确的要怎么写

我先贴错误弹出框,不管怎么弄他都把整个页面乱七八糟的弹回来了:
求大神来帮忙,做购物车的时候jquery的ajax返回值出有关问题了

下面我贴代码:jquery部分:

            var sizeid = $("#hid_sizeid").val(); //这是尺码ID,有值
            var colorid = $("#hid_colocid").val();//这是颜色ID,有值
            $.ajax({
                url: "ajax.aspx?colorid=" + colorid + "&sizeid=" + sizeid + "",
                type: "post",
                datatype: "json",//类型我用string,html,text都试过效果一样
                success: function (result) {
                    alert(result);
                }
            });

ajax.aspx.cs页面代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class ajax : System.Web.UI.Page
{
    public int ProNum = 0;//产品库存
    public int waringNum = 0;//预警值
    public decimal priceNor = 0;//普通价
    public decimal PriceSale = 0;//站点价
    public decimal PriDiscount = 0;//折扣率
    DataSet ds = new DataSet();
    DataSet dt = new DataSet();
    Maticsoft.DAL.ProductDetail _ProductDetailDAL = new Maticsoft.DAL.ProductDetail();//这是数据层   
 Maticsoft.Model.ProductDetail _ProductDetailModel = new Maticsoft.Model.ProductDetail();//这是实体层
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int productdetailId = 0;
            int colorid = Convert.ToInt32(Request.QueryString["colorid"]);
            int sizeid = Convert.ToInt32(Request.QueryString["sizeid"]);
            IDataParameter[] parameters = new SqlParameter[2];
            parameters[0] = new SqlParameter("@Color", SqlDbType.Int);
            parameters[1] = new SqlParameter("@Size", SqlDbType.Int);
            parameters[0].Value = colorid;


            parameters[1].Value = sizeid;
            ds = Maticsoft.Public.Page.RunProcedure("Color_Size", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                productdetailId = Convert.ToInt32(dr["ProductDetailID"]);
                dt = _ProductDetailDAL.GetList(" ProductDetailID=" + productdetailId);
                if (dt.Tables[0].Rows.Count > 0)
                {
                    ProNum = Convert.ToInt32(dt.Tables[0].Rows[0]["ProductNum"]);
                    priceNor = Convert.ToDecimal(dt.Tables[0].Rows[0]["PriceNormal"]);
                    PriceSale = Convert.ToDecimal(dt.Tables[0].Rows[0]["PriceThisWeb"]);
                    PriDiscount = Convert.ToDecimal(dt.Tables[0].Rows[0]["Discount"]); 

//到这一步这四个都有值,打算返回去的,我下面只返回一个产品num,不知道怎一起返回去前台用,转换的JSON没弄过,同求方法。
                }
                Response.Write(ProNum);
            }
        }
    }
[解决办法]

Response.Write(ProNum);
Response.End();/////////结束aspx页面内的html代码输出,要么就把aspx页面内的html代码全部删除

[解决办法]
把后台的Page_Load()改成返回int类型的,
Response.Write(ProNum);换成return ProNum;试试

热点排行