I'm having issues with ajax json requests and Internet Explorer.
Specifically ajax requests do not behave properly.
I'm using:
OpenCart 1.5.3.1
jquery-1.7.1.min.js
jquery-ui-1.8.16.custom.min.js
Internet Explorer 9
PHP 5.2.9
This is the request function:
function addToCart(product_id, quantity, option_id, option_value) {
quantity = typeof(quantity) != 'undefined' ? quantity : 1;
option_value = typeof(option_value) != 'undefined' ? option_value : 0;
option_id = typeof(option_id) != 'undefined' ? option_id : 0;
jQuery.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
cache: false,
data: 'product_id=' + product_id + '&quantity=' + quantity + '&option_id=' + option_id + '&option_value=' + option_value+'&rnd=' + Math.random(),
dataType: 'json',
success: function(jsonObj) {
$('.success, .warning, .attention, .information, .error').remove();
if (jsonObj['redirect']) {
location = jsonObj['redirect'];
}
if (jsonObj['success']) {
$('#notification').html('<div class="success" style="display: none;">' + jsonObj['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.success').fadeIn('slow');
$('#cart-total').html(jsonObj['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
}
});
}
The PHP function return:
{"success":"Added to cart!","total":"1 product(s) - 52,48\u043b\u0432."}
This all works fine in Chrome, FF etc. but fails in IE.
Actually IE does not fire a "success" event.
The only way I can get a response is through an error handler.
Then the json object has a status = 200 and statusText = OK
This is the json object after success event fired in Chrome:
jsonObj: Object
success: "Added to cart!"
total: "1 product(s) - 52.48лв."
__proto__: Object
From which the 'success' and 'total' values are used.
This is the json object after the error event was handled in Internet Explorer:
The responseText is a string that contains the current page html source.
I've tried with jQuery.ajaxSetup({cache: false});
but the result is the same.
Has anyone had this issue? Or any tips?
I have no more ideas.