Search code examples
ajaxbest-buy-api

Searching multiple categories in the Best Buy Api


Hello I am working on a search engine website that allows you to look up products using the Best Buy Api and right now I am having trouble being able to search for products within different categories. Right now I am able to search for items in a single category. For example, I can look up items that are in the laptop category but can't look up items that are in the cell phone category. Here's my code so far:

$.ajax({
        type: "GET",
        url: "http://api.bestbuy.com/v1/products(search=" + input + "&categoryPath.id=pcmcat209400050001)?apiKey=KEY HERE&pageSize=20&format=json&callback=?",
        cache: true,
        dataType: 'json',
        success: function(data) {
            alert('success');
            console.log(data);

            for(var i=0; i , data.products.length; i++) {

                var result = data.products[i];

                productList.append(
                '<img src="'+ result.mediumImage +'"/>'
                + '<h3>'+ result.name +'</h3>'
                + '<p>'+ result.shortDescription +'</p>'
                + '<p>$'+ result.regularPrice +'</p>');
            }
        },

        });

This example will allow you to search for any items that are in the cell phone category. My newxt idea was to try and do multiple queries at once but that only allows you to search for products of the last ajax call and not the one above it. Any help would be greatly appreciated.


Solution

  • By changing my dataType to jsonp I am now able to do multiple queries.