I'm trying to loop all the items in the product array. Using an ajax call I get the following response from the API:
productData = {"product":[{"id":"9200000083451240","title":"Apple Lightning Cable"},{"id":"9200000098453451","title":"Apple iPhone XR"}],"totalResultSize":2}
As you can see the data I need is inside a variable "productData", how do I access it from my AJAX response data?
I've tried data.productData.product and some other stuff but nothing works.
var searchTerm = $("#searchterm").val();
$.ajax({
url: 'https://api.com/search?term=' + searchTerm,
type: 'GET',
}).done(function (data) {
$.each(data.productData.product, function (index, element) {
console.log(element.title);
});
console.log('---- Data ----');
console.log(data);
});
Please help.
productData =from the startdata.productand your logic will work.