/    Sign up×
Community /Pin to ProfileBookmark

Race Situation

I am pretty sure I am creating a race but I do not know how to go about fixing it… any ideas?

cheers,

[code=php]
$(‘.add-items’).live(‘click’, function(evt) {
if (evt.button != 0) return; // ignore right-click
evt.preventDefault();

var items = $(this).attr(‘href’).substr(1).split(‘,’);
// now items is [‘G400180’, ‘G400181’]

// Disable the link to prevent repeated orders
$(this).attr(‘disabled’,’disabled’);

// Execute the orders using ajax
var remaining_requests_cnt = items.length;
for (var i = 0; i < items.length; i++) {
$.ajax({
url: ‘/cgi/cart.cgi?’+items[i],
success: function() {
if (–remaining_requests_cnt == 0) {
top.location.href=”http://www.feelgoodlightups.com/cgi/cart.cgi?viewcart”;
}
},
error: function() {
alert(‘Error occurred. Check the content of your cart.’);
location.reload();
},
})
}
});[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@bfly03authorApr 16.2010 — ok this is what i have so far... any ideas on why it is not working?

cheers,

[code=php]$('.add-items').live('click', function(evt) {
if (evt.button != 0) return;
evt.preventDefault();

var items = $(this).attr('href').substr(1).split(',');
function mySuccess() {
if (items.length > 0) {
addItemToCart(items.pop());
} else {
top.location.href = 'http://www.feelgoodlightups.com/cgi/cart.cgi?viewcart';
}
}
function addItemToCart(itemId) {
$.ajax({
url: '/cgi/cart.cgi?'+itemId,
success: mySuccess,
error: function() {
alert('Error occurred. Check the content of your cart.');
location.reload();
},
})
}
});[/code]
Copy linkTweet thisAlerts:
@BIOSTALLApr 16.2010 — It's hard to say without knowing what exactly you are trying to achieve, whats happening with your current code (any errors?) and what the rest of your code looks like.

A couple of pointers that I hope will help you out though:

  • 1. Is the 'addItemToCart(itemId)' function being called anywhere? From what I can see there are two functions calling each other but not one of them being called externally :-S

  • 2. Try adding alerts (eg 'alert("I am here")') at various points through your code to see how far it is getting. If you don't receive a certain alert you know the code isn't getting to it. A process of elimination is the best form of debug ?


  • Hope that helps somewhat.
    ×

    Success!

    Help @bfly03 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...