Reputation: 11
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
Reputation: 28160
Two tips:
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.Upvotes: 1
Reputation: 7076
try adding an event.preventDefault()
to the submit function
source: http://api.jquery.com/event.preventDefault/
Upvotes: 0