In my home page there is product listing. Each product contains a button called "Add to Cart". On clicking it is adding into the cart and a pop up is showing telling "your product has been added to the cart". I want to show the respective product name in the pop up .
Following is the ajax code while clicking on the button..

jQuery('#buy_<?php echo $_product->getId(); ?>').click(function() { 
    url: '/ajax/index/add',
    dataType: 'json',
    type : 'post',
    data: { isAjax: 1, qty: 1, product: jQuery(this).data('product-id') },
    success: function(data){

return false;
<div id="add-product-container" class="jqmWindow">
    <ul class="messages clearfix" id="add-product">
        <li class="success-msg">
            <span class="spnPrdname"><?php echo "PRODUCT NAME"; ?></span> 
            <span>has been added to <a href="<?php echo $this->getUrl('checkout/cart'); ?>" class="text-link">your basket</a>.</span>

You need to return product name from ajax contoller IndexController.php addAction function. Then Using JavaScript replace span#spnPrdname content


  • Unable to find the file url: '/ajax/index/add'. There is no module named "ajax" exists.. But products get added to cart. That means it is redirecting to some where. Can u please help me in this regard ? Sep 24 '15 at 7:48
  • this module router name.. You can find any of your 3rd parlty extension
    – Amit Bera
    Sep 24 '15 at 8:05
  • Yes . I found It . Now it is working .Thanks @Amit Bera Sep 24 '15 at 9:31
  • you are welcome :)
    – Amit Bera
    Sep 24 '15 at 9:34

I'm assuming you mean to replace `` with the proper product name.

That said:

<?php echo "PRODUCT NAME"; ?> should be <?php echo $_product->getName() ?>

  • But, I'm starting to wonder if you are repeating/iterating this script through every item on your homepage? Sep 23 '15 at 23:49
  • Every product tile in the page has a button called "Add to cart". On clicking it, the above code executes. I am getting the product_id and product_name before the button click. But don't know how to show it on that <?php echo "PRODUCT NAME"; ?>. Sep 24 '15 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.