Documentation You are here: start » v » 2.0 » json

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v:2.0:json [2019/09/09 05:38] – [Making a JSONP call to the cart] adamv:2.0:json [2022/02/04 16:37] (current) – [Adding a Coupon or Session Value Automatically Using JSONP] adam
Line 50: Line 50:
 <code javascript> <code javascript>
 FC.client.on('ready.done', function () { FC.client.on('ready.done', function () {
 +  // Automatically add a coupon
   if ($.isEmptyObject(FC.json.coupons)) {   if ($.isEmptyObject(FC.json.coupons)) {
     FC.client.request('https://'+FC.settings.storedomain+'/cart?coupon=YOUR_COUPON_CODE').done(function() {     FC.client.request('https://'+FC.settings.storedomain+'/cart?coupon=YOUR_COUPON_CODE').done(function() {
Line 57: Line 58:
     });     });
   }   }
 +  // Add a hidden session variable
 +  FC.client.request('https://'+FC.settings.storedomain+'/cart?h:foo=bar');
 }); });
 </code> </code>
Line 62: Line 65:
 This function hooks into the ''ready.done'' event to ensure that the FoxyCart JSON object has been loaded, and checks if the coupons object is empty. If it is, it then triggers the request to add a coupon to the cart, and removes any coupon errors in case it's expired or removed. This is just a simple example, but hopefully gives you an idea of how to get started. This function hooks into the ''ready.done'' event to ensure that the FoxyCart JSON object has been loaded, and checks if the coupons object is empty. If it is, it then triggers the request to add a coupon to the cart, and removes any coupon errors in case it's expired or removed. This is just a simple example, but hopefully gives you an idea of how to get started.
  
-If you want to run code like that on pageload, you'd need to wrap it in the [[.:javascript#accessing_the_fc_object_on_your_own_website|FC.onLoad() wrapper]], like this:+If you want to run code like that on pageload //of your own website//, you'd need to wrap it in the [[.:javascript#accessing_the_fc_object_on_your_own_website|FC.onLoad() wrapper]], like this:
 <code javascript> <code javascript>
 var FC = FC || {}; var FC = FC || {};

Site Tools