Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
\\
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:language=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

// 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.
 \\