Magento – Ajax add to cart does not always work

ajaxmagento-1.9

When adding to cart, I only sometimes get the stylish Ajax "Your item was added to cart"-popup. Other times I get the ugly standard magento added to cart orange and grey buttons. When I get the default behaviour, I can't see the items in cart before refreshing the page, so I suspect it's some kind of ajax error. I have captured both Ajax requests and they are quite different. Can someone figure out the error?

Works:

$.get('http://www.propagandashop.dk/proaddto/index/add/uenc/aHR0cDovL3d3dy5wcm9wYWdhbmRhc2hvcC5kay8,/product/754/form_key/vRnRi3VEvUkNw6xa/isAjax/1')
  .done (showResult)
  .fail(showError);


  {
  "frameId": 0,
  "method": "GET",
  "parentFrameId": -1,
  "requestId": "13544",
  "tabId": 57,
  "timeStamp": 1440573329737.51,
  "type": "xmlhttprequest",
  "url": "http://www.propagandashop.dk/proaddto/index/add/uenc/aHR0cDovL3d3dy5wcm9wYWdhbmRhc2hvcC5kay8,/product/754/form_key/vRnRi3VEvUkNw6xa/isAjax/1"
}

Doesnt work:

First get:

var queryData = {
  "block[]": "options",
  "awacp": "1",
  "no_cache": "1"
};
$.get('http://www.propagandashop.dk/checkout/cart/add/uenc/aHR0cDovL3d3dy5wcm9wYWdhbmRhc2hvcC5kay9rb2trZW4,/product/235/form_key/vRnRi3VEvUkNw6xa/', queryData)
  .done (showResult)
  .fail(showError);


  {
  "frameId": 0,
  "method": "GET",
  "parentFrameId": -1,
  "requestId": "13875",
  "tabId": 57,
  "timeStamp": 1440573421999.0598,
  "type": "xmlhttprequest",
  "url": "http://www.propagandashop.dk/checkout/cart/add/uenc/aHR0cDovL3d3dy5wcm9wYWdhbmRhc2hvcC5kay9rb2trZW4,/product/235/form_key/vRnRi3VEvUkNw6xa/?block%5B%5D=options&awacp=1&no_cache=1"
}

Second get (same time):

var queryData = {
  "actionData": "{\"added_product\":\"235\"}",
  "block[]": [
    "cart",
    "sidebar",
    "topLinks",
    "skipLinks",
    "wishlist",
    "miniWishlist",
    "addProductConfirmation",
    "removeProductConfirmation"
  ],
  "awacp": "1",
  "no_cache": "1"
};
$.get('http://www.propagandashop.dk/kokken', queryData)
  .done (showResult)
  .fail(showError);

  {
  "frameId": 0,
  "method": "GET",
  "parentFrameId": -1,
  "requestId": "13876",
  "tabId": 57,
  "timeStamp": 1440573422599.8179,
  "type": "xmlhttprequest",
  "url": "http://www.propagandashop.dk/kokken?actionData=%7B%22added_product%22%3A%22235%22%7D&block%5B%5D=cart&block%5B%5D=sidebar&block%5B%5D=topLinks&block%5B%5D=skipLinks&block%5B%5D=wishlist&block%5B%5D=miniWishlist&block%5B%5D=addProductConfirmation&block%5B%5D=removeProductConfirmation&awacp=1&no_cache=1"
}

Best Answer

Are you using caching of some sort, e.g. Varnish? If so please check your whitelist options. Sometimes ajax requests are cached thus returning different responses. Also, since you seem to be using an extension for the ajax cart make sure to check the developer docs.