I have a problem with the following code, which doesn’t want to work in Chrome and Safari:
function updateBasket(data) {
if (data != '') {
$.each(data, function(k, v) {
if (jQuery.inArray(k, data.remove) == -1 && $('.' + k).length > 0) {
$('.' + k).html(v);
}
});
}
}
$('.add_to_basket').live('click', function() {
var button = $(this);
var classes = $(this).attr("class");
var identity = $(this).attr("rel").split('_');
var url = '/basket/action/add/type/' + identity[0] + '/id/' + identity[1];
$.ajax({
type: 'POST',
url: url,
data: ({ cls : classes }),
dataType: 'json',
success: function(data) {
if (!data.error) {
updateBasket(data);
button.replaceWith(data.button);
}
}
});
return false;
});
The .add_to_basket trigger only works with the first click – after that it doesn’t do anything.
It works fine with Firefox and IEs, but for some reason Chrome and Safari doesn’t seem to like it.
Here’s the json response which comes after first click:
{
"error": false,
"items": {
"27": {
"price": "120.00",
"qty": 1,
"discount": 0,
"vat": 0,
"price_vat": 120
}
},
"bundles": [],
"no_of_items": 1,
"sub_total": "£120.00",
"vat_total": "£0.00",
"total": "£120.00",
"remove": ["remove", "error", "button", "items", "basket"],
"button": "<a href=\"#\" class=\"button button_red add_to_basket\" rel=\"item_27\">Remove from the basket<\/a>"
}
and the one which comes after second one (returning to the initial state):
{
"error": false,
"items": [],
"bundles": [],
"no_of_items": 0,
"sub_total": "£0.00",
"vat_total": "£0.00",
"total": "£0.00",
"remove": ["remove", "error", "button", "items", "basket"],
"button": "<a href=\"#\" class=\"button button_blue add_to_basket\" rel=\"item_27\">Add to the basket<\/a>"
}
Any idea what I’m doing wrong here?
To make it even difficult – this is only happening with Chrome and Safari on Mac OSX 10.5 (Leopard) – but doesn’t on Snow Leopard – using the same versions of browsers (Chrome 11.0.696.71)
Just an update – I’ve done a few tests and it appears to be a problem with SESSIONS. It doesn’t allow me to log in either – meaning session is not created when using Chrome or Safari on Mac OS X 10.5.
Any idea?
Ok – I’ve figured out what was causing problems:
which should simply be:
as it checks on its own whether the session is set.
Thanks for participating everyone!