...
All
...
API
...
calls
...
are
...
synchronous
...
unless
...
you
...
specify
...
an
...
optional
...
last
...
parameter
...
at
...
the
...
end
...
of
...
the
...
function
...
call.
...
Below
...
we'll
...
show
...
you
...
how
...
to
...
make
...
an
...
asynchronous
...
call.
...
Example
...
of
...
synchronous
...
code
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| =javascript|linenumbers=true|theme=DJango}
| |||||||
// Make the API call var shippingEstimates = estimateShipping(); // Consume the result for (var = i; i < shippingEstimates.length; i++) { // Do something with the estimate } {code} |
Example
...
of
...
asynchronous
...
code
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// Define a callback function
function myCallbackFunction(shippingEstimates){
for (var = i; i < shippingEstimates.length; i++) {
// Do something with the estimate
}
}
// Make the asynchronous call
estimateShipping({'async': true, 'onComplete': myCallbackFunction});
|
Our
...
recommendation
...
is
...
to
...
make
...
the
...
the
...
shipping
...
estimate
...
call
...
asynchronous
...
due
...
to
...
the
...
time
...
it
...
can
...
take
...
calculate
...
estimates.
...
Make
...
sure
...
that
...
you
...
give
...
the
...
customer
...
a
...
visual
...
indication
...
that
...
shipping
...
estimates
...
are
...
being
...
calculated.
...
We
...
do
...
not
...
recommend
...
making
...
calls
...
that
...
manipulate
...
the
...
cart
...
asynchronous
...
as
...
it
...
could
...
cause
...
inconsistancies
...
in
...
the
...
global
...
cart
...
variables
...
contents.
...