开发者

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").fadeI开发者_如何学Pythonn("fast");
                    $('#content_total').fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast");
                }, 1300);
            }
        });
        $('#button_submit').attr('disabled', '');
        return false;
    });
});


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).


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜