Hi,

I'm using the big cartel framework to build a site, and am trying to make an AJAX call - currently without success. My code is as follows:

jQ('body').on('click','#closeDetails',function(){

    // If necessary condition met
    if (jQ('#productDetails').attr('class') != undefined){

        // Store appropriate category
        var destCategory = jQ('#productDetails').attr('class').toLowerCase();

        // Attempt to alert products from category
        // Taken from 
        jQ(function() {
            Product.findAll({ category: destCategory }, function(products) {
                alert("I found " + products.length + " products!");
            });
        });

    } else {
        // Code that works goes here
    }
});

So, when the user clicks on #closeDetails - if the condition returns true - find the correct category value (works fine), then use this value to try and retrieve all products from the category, and (for now) simply alert the number found.

Currently the alert simply says "Error:" and Chrome's console says "Failed to load resource: the server responded with a status of 404 (Not Found) - http://www.webaddress.co.uk/products.js?category=category1".

I've only been working with javascript for a few weeks, so am guessing I've made a syntax error. What am I doing wrong?

Thanks.

Dani AI

Generated

Short summary and a focused checklist for the 404 on Big Cartel AJAX (referring to and ):

AJAX calls that use Big Cartel’s Theme JavaScript API (the global Product helpers) will 404 or fail when the API script isn’t present, when the category value passed isn’t the category permalink (slug), or when the store is not publicly accessible (maintenance/offline). ’s question about where Product comes from is spot on — it’s provided by Big Cartel’s theme API. (developers.bigcartel.com)

Quick checklist to troubleshoot (do these in order):

  • Confirm the theme includes the Theme JS API and that the script has loaded before your code runs (the API is intended to run inside store pages, not from an external domain). (developers.bigcartel.com)
  • Verify the category you pass is the category permalink (slug) exactly as the theme expects — lowercasing alone may not match hyphens/spaces or custom permalinks. Inspect the request the helper makes in DevTools -> Network to see the requested path. (developers.bigcartel.com)
  • If the store is in Maintenance mode, public requests can be blocked; test with Maintenance mode turned off or while logged in as the shop owner. ’s intermittent success after refreshing is consistent with maintenance/admin visibility behavior. (bigcartel.com)

Other notes and caveats:

  • If you’re testing in a Big Cartel development environment (Dugway or similar), behavior can differ from a live shop (some dev environments return a fixed set or behave oddly). If results look inconsistent, test on a live/published store or as the logged-in admin. (stackoverflow.com)
  • Quick console check to confirm the API is present before calling it:
console.log('Product' in window ? 'BigCartel API loaded' : 'Product API missing');

When the API is present and you supply the correct category permalink, Product.findAll calls should return JSON rather than a 404. If a 404 persists, capture the Network request and response details (requested URL, response status/body) and compare the category slug to the actual category permalink in the store.

Recommended Answers

All 2 Replies

Maybe I'm missing something, butI see line 12 has Product.findAll but I don't see where you define Product anywhere?

I should've made it clearer - that's part of Big Cartel's native javascript - the URL in the comment above shows where I got that piece of code from.

Edit - It seems that this could be an issue with testing in maintenance mode. After a couple of page refreshes and visiting some other pages, and then trying it, it works ok.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.