I have a simple class named Basket, I want to set my products with ajax method. Please look at the example below:
class Basket
{
constructor()
{
this.products = [];
this.setProducts();
console.log(this.products); // still empty
}
setProducts()
{
var self = this;
$.ajax({
'url': getProductsUrl,
'method': 'GET',
success: function(resp) {
console.log(resp.products); // I can see products returned from api
self.products = resp.products
},
error: function(resp) {
// err
}
});
}
The problem is that products are not set. resp.products
variable is returned well and in proper json format.