Matt
Matt

Reputation: 11

Jquery script works in all browsers except IE8 and lower

I am running an ecommerce shop and the following script is used to add an item to the cart without a page reload. It works in all major browsers including IE9 but it just does the default page reload with IE8 and below. No errors show but it reloads the page which it IS NOT supposed to do. Here is the code-

$(document).ready(function() {
    $('#cart_quantity').live('submit', function() {
        $('#button_submit').attr('disabled', 'disabled');

        var options = {};

        options = { to: "#ajax_cart", className: 'ui-effects-transfer' };

        $("#button_add_cart").effect('transfer',options,1300);

        var datas_form = $('#cart_quantity').serializeArray();
        $.ajax({
            url:'ajax_add_cart.php',
            data: datas_form,
            type: 'POST',
            success: function(data) {
                var datas = data.split("|");
                setTimeout(function() {
                    $('#content_products').html(datas[0]);
                    $('#content_total').html(datas[1]);
                    $('#fila_' + datas[2]).fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast");
                    $('#content_total').fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast");
                }, 1300);
            }
        });
        $('#button_submit').attr('disabled', '');
        return false;
    });
});

Upvotes: 1

Views: 424

Answers (2)

Tgr
Tgr

Reputation: 28160

Two tips:

  1. add e.preventDefault() to the beginning of the handler. Any error in the handler will result in return false not executing and the browser performing the default action unless preventDefault was called before the error.
  2. avoid live submit handlers, they are simulated in old IE via the click handler (as submit events do not bubble), which can lead to various perks (see e.g. bug 7061).

Upvotes: 1

Brombomb
Brombomb

Reputation: 7076

try adding an event.preventDefault() to the submit function

source: http://api.jquery.com/event.preventDefault/

Upvotes: 0

Related Questions