Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:03:33+00:00 2026-06-14T19:03:33+00:00

On my site i am loading shopping products with the add to cart-button dynamically

  • 0

On my site i am loading shopping products with the “add to cart”-button dynamically with a jquery ajax call. For the shopping cart itself, I use jcart, jquery plugin.

When I then add an item to the cart, jcart calls a php-file with ajax and POST. All works fine, the products are correctly added to the cart, but the page reloads every time I add an item to the cart.
When I don’t use the ajax call to load the products (e.g. load them directly in the page), all works fine, so there must be a conflict somewhere.
Any clues?

This is my products-function and the html.

...
<script>
      function loadProducts(str) {
             $.ajax({
                   type: 'GET',
                   async: true,
                   url: 'ajax/load.php',
                   data: {'max-id' : str},
                   cache: false,
                   success: function(response) {
                        $('#products').html(response).fadeIn('slow');
                   },
                 });
        }
</script>

<script>
     $(document).ready(function() {
        var n = '';
       loadProducts(n);
     });
</script>

<script src="jcart/js/jcart.js"></script>

</body>
</html>

The jcart-Plugin with its ajax-call can befound here:
http://conceptlogic.com/jcart/standalone-demo/jcart/js/jcart.js

Here are the functions from jcart.js.

            $.ajaxSetup({
            type: 'POST',
            url: path + '/relay.php',
            cache: false,
            success: function(response) {
                // Refresh the cart display after a successful Ajax request
                container.html(response);
                $('#jcart-buttons').remove();
            },
            error: function(x, e) {
                ...
            }
        });

…

    function add(form) {
        // Input values for use in Ajax post
        var itemQty = form.find('[name=' + config.item.qty + ']'),
            itemAdd = form.find('[name=' + config.item.add + ']');

        // Add the item and refresh cart display
        $.ajax({
            data: form.serialize() + '&' + config.item.add + '=' + itemAdd.val(),
            success: function(response) {

                // Momentarily display tooltip over the add-to-cart button
                if (itemQty.val() > 0 && tip.css('display') === 'none') {
                    tip.fadeIn('100').delay('400').fadeOut('100');
                }

                container.html(response);
                $('#jcart-buttons').remove();
            }
        });
    }

…

    // Add an item to the cart
            // is called from the submit-buttons within each product picture
    $('.jcart').submit(function(e) {
        add($(this));
        e.preventDefault();
    });

The “loadProducts()” function puts this into #products container for each item:

<form method="post" action="" class="jcart">
    <fieldset>
        <input type="hidden" name="jcartToken" value="<?php echo $_SESSION['jcartToken'];?>" />
        <input type="hidden" name="my-item-id" value="SDK12345" />
        <input type="hidden" name="my-item-name" value="Product Name" />
        <input type="hidden" name="my-item-price" value="1.00" />
        <input type="hidden" name="my-item-qty" value="1" />
        <ul>
            <li><img src="product-image.jpg"/></li>
            <li>1.00 Dollar</li>
            </ul>
        <input type="submit" name="my-add-button" value="Add to cart" class="button" />
    </fieldset>
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:03:36+00:00Added an answer on June 14, 2026 at 7:03 pm

    Ok, I found the solution.

    As the forms are loaded via ajax, they were no correctly interpreted by jcart.js (though the functions all worked fine for themselves).

    “bind” didn’t work, but “live” fixed it:

    $('.jcart').live('submit',function(e) {
      add($(this));
      e.preventDefault();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering will my site perform loading faster if the images that I use
For the moment, we're loading site-wide event-listeners from a single common.js file for a
I just need some advice on if this is wise. I'm loading my site
I have designed a site and my CSS is not loading in FF and
I'm loading some feeds and displaying them as links on my site page. When
I ran into a problem loading the admin section of my django site with
I just got this site sent to me because a page is not loading,
$('a').click(function(event){ $('body').html('loading...'); $.post('www.sitename.com/hello',{site:http//:www.google.com},function(data) { alert(data); }); event.preventDefault(); }); I am using the above script
In Python, I'm getting an error because it's loading a module from /usr/lib/python2.6/site-packages but
While investigating a reported problem with my site loading slowly, I came across an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.