??yy 2012-08-07 11:58 采纳率: 0%
浏览 36

AJAX时旋转光标

I have a WebGrid in a lot of my pages that list products. And I have the following code that adds the item to the database that the user clicked on:

        public bool ToCart(int userId,
            string partNumber,
            string productDescription,
            int units,
            int boxes,
            decimal unitPrice,
            decimal boxPrice,
            decimal lineTotal,
            string orderId,
            DateTime dateTime,
            bool isBoxed)
        {
            bool addedToCart = false;

            try
            {
                Cart cart = new Cart()
                {
                    UserId = userId,
                    PartNumber = partNumber,
                    Description = productDescription,
                    Units = units,
                    Boxes = boxes,
                    UnitPrice = unitPrice,
                    BoxPrice = boxPrice,
                    LineTotal = lineTotal,
                    OrderId = orderId,
                    OrderDate = dateTime,
                    IsBoxed = isBoxed
                };

                database.AddToCarts(cart);
                database.SaveChanges();

                addedToCart = true;
            }
            catch (Exception exception)
            {
                addedToCart = false;
                Console.Write(exception.Message);
            }

            return addedToCart;
        }

The call to this method, looks like:

ToCart(WebSecurity.CurrentUserId, PartNumber, ProductDescription, Units, Boxes, UnitPrice, BoxPrice, LineTotal, OrderId, DateTime.Now, IsBoxed)

Now I want to make this into an AJAX post. But I don't want anything fancy. I would just like to have the normal WaitCursor or BusyCursor show up while this is being added to the cart, and to display a <p>item added to cart</p> at the top of the page, when it has been added to the cart.

enter image description here

How can I accomplish this when a user clicks on an item they wish to add to their cart?

  • 写回答

3条回答 默认 最新

  • perhaps? 2012-08-07 14:14
    关注

    I suggest you use the BlockUI plugin for that:

    $('.addToCart').click(function(){
     $.ajax({
           before: function(){$('body').block()} ,//will be called before the ajax call begins
           complete: function(){$('body').unblock()}, //will be called when ajax completes, whether with error or success
           //on success, append message to top
           success: function(){
                  var message = "<p>item added to cart</p>";
                  $(message).appendTo('.topDiv');
        }
    
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统