היי אנשים.
יש לי בעיה עם jQuery/setTimeout. אני חושב שזה עם הjQuery
כי כשעשיתי שcloseMsg תציג alert הsetTimeout עבד מעולה.
הקוד עובד בסדר, אין בו שגיאות למי שתוהה (חוץ מסגירת ההודעה).
פשוט ברגע שאני כותב בsetTimeout דיליי שהוא יותר גדול מ900 זה לא עובד.
הנה הפונקצייה:
PHP קוד:
function addSelectedItems(form, cat) {
var products = [];
var count = 0;
var countAdd = 0;
var msg = "";
// get the products number
var j = 0;
$("input.amount").each(function() {
j++;
count++;
amount = $('#amount' + j).val();
if (amount > 0)
countAdd++;
});
for (var i = 1; i <= count; i++) {
if (i == 1) {
$("#AddToShoppingCart").fadeIn("slow");
$("#ShoppingCartMsg").html("the products were added to your shopping cart");
} else {
if ((i - 1) == countAdd) {
setTimeout('closeMsg();',1000);
}
}
var amount = $('#amount' + i).val();
if (amount > 0) {
var colorObj = document.getElementById('color-' + i);
if (colorObj) {
color = colorObj.options[colorObj.selectedIndex].value;
} else {
color = "default";
}
var catalog_number = $('#catalog_number' + i).val();
var time = new Date().getTime();
var serverPage = 'index.php?module=cart&advanced=true&ajax=true&act=addProduct&catalog_number=' + catalog_number + '&amount=' + amount + '&color=' + color + '&time=' + time;
$.get(serverPage);
MiniCart(false); // updates MiniCart
document.getElementById('items').innerHTML = getItems();
var mktime = new Date().getTime();
if (cat != "") {
var loadPage = 'index.php?module=catalog&act=categories&id=' + cat + '&ajax=true&time=' + mktime;
$.get(loadPage, function(server) {
$("#products-list").html(server);
})
} else {
var page = document.getElementById("page").value;
$.get(page+"&time="+mktime, function(server) {
$("#products-list").html(server);
});
}
}
}
}
הפונקצייה closeMsg:
PHP קוד:
function closeMsg() {
$("#ShoppingCartMsg").html("TESTING");
}
תודה לעוזרים
