0

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.

Edited by chr.s

2
Contributors
2
Replies
14
Views
4 Years
Discussion Span
Last Post by chr.s
0

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

0

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.

Edited by chr.s

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.