title: Jquery Shopping Cart Plugin: Implementing Session Management
body: <p>Am using jquery shopping cart <a href="http://plugins.jquery.com/project/smartcart2" rel="nofollow">http://plugins.jquery.com/project/smartcart2</a>
  Can anyone help me in implementing onAdded, onRemoved, onUpdated methods in order to make Ajax call to maintain session on the server side.
  I make the Ajax request on the server whenever an object is added/removed/updated and get the data back in JSON format. I update the qty like <code>obj.attr("qty", eval(msg)[1]);</code> with the updates from server. 
  However, if i hit refresh or the table data is repopulated the cart items are no longer there. So, the question really is how to populate the data from session so that the product would still remain in the shopping cart upon refresh etc.</p>
  
  <pre><code>$('#SmartCart').smartCart({ 
  onAdded: function(pObj,quantity){ cartAdded(pObj,quantity);}, 
  onRemoved: function(pObj){ cartRemoved(pObj);},
  onUpdated: function(pObj,quantity){ cartUpdated(pObj,quantity); },
  });
  
  function cartAdded(obj,qty){
  var product_id = obj.attr("pid");
  var quantity = qty; 
  // Ajax calls for adding product to cart
  function(pObj,quantity){
      cartAdded(pObj,quantity);}
  }
  
  function cartRemoved(obj){
  var product_id = obj.attr("pid");
  // Ajax call for removing product from cart
  }
  
  function cartUpdated(obj,qty){
  var product_id = obj.attr("pid");
  var quantity = qty; 
  // Ajax call for updating product on cart
  }
  
  function cartAdded(obj,qty){
              var partNum = obj.attr("partNumber");
              var quantity = qty;                
           $.ajax({
          type: 'POST',
          url: "json/sessionManager",
          data : "partNum=" + partNum + "&amp;qty=" + quantity,
          dataType: "text/json",
          success: function(msg){
              obj.attr("qty", msg[1]);
          },
          error: function(httpRequest, textStatus, errorThrown) {
             alert("status=" + textStatus + ",error=" + errorThrown);
          }
      });  
          }
  </code></pre>
  
  <p>I would highly appreciate recommendations around the same.</p>