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 http://help.bigcartel.com/customer/portal/articles/772751-javascript-ajax
        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.

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.