Forum: Rails Spinoffs (closed, excessive spam) form.request() and onComplete/onSuccess

F8ce5331e47a2727baba2ee0a77d2866?d=identicon&s=25 WebbedIT (Guest)
on 2008-07-07 21:11
(Received via mailing list)
Hi all,

I did a search on onComplete here and on Google but didn't find the
answer to what is probably a simple enough problem to resolve for
someone who uses javascript/prototype more than me.

I am creating a shopping cart and I'm using form.request() when adding
a product to the cart which is working really well including the
addition of various options for each product.

However once I have added each item I want to update the Cart Overview
from "You have no items in your cart" to "You have XX items totalling
£XX.XX in your cart".

I am using the following which is doing as it should but a bit too
fast:

onClick=\"$('shopCartAdd').request({
  onComplete: updater({container: 'shopCartOverview', action:
'shopCartUpdate'})
});\"

but the onComplete is firing before my php script has updated the cart
table so it simply refreshes the overview content rather than updating
it with the new product count and total.

I have tried using onSuccess as well but I am assuming AJAX deems
getting a connection to the script as a success so ploughs on at
lightening speed.  Anyway of stopping the onComplete/onSuccess from
firing until my php script has done it's thing with the form data?

Paul.
F490e41cd5de1393a9f6958b70dae6ab?d=identicon&s=25 Frederick Polgardy (Guest)
on 2008-07-07 21:19
(Received via mailing list)
This doesn't work: you're calling updater(...) first and then assigning
the
result to your onComplete handler.

onClick = $('shopCartAdd').request({
  onComplete: function(xhr) {
    updater({container: 'shopCartOverview', action: 'shopCartUpdate'});
  }
});

-Fred

On Mon, Jul 7, 2008 at 1:46 PM, WebbedIT <paul@webbedit.co.uk> wrote:

> it with the new product count and total.
--
Science answers questions; philosophy questions answers.
This topic is locked and can not be replied to.