0

I'm using this function

function returnDatas(param) {
    return param;
}

function getCartProducts(id, callback){
   $.post(path, {id: parseInt(id)}, function(data){
        callback(data); // data value can be 'true' or 'false'
   });
}

var isData = getCartProducts(1, returnDatas);
if( isData ){
   // true
}

it doesn't work for me basically I want to pass the data from the $.post to a variable outside the post.

  • Take a look at [this answer](https://stackoverflow.com/a/16987871/16688813). – Tom Jan 21 '22 at 14:39
  • You are successfully passing the result of the POST operation to the `returnDatas` function. The problem is that function doesn't do anything with that result. It just returns it back to the caller, who already had the result in the first place. You're expecting `getCardProducts` to return something, but it doesn't. It looks like whatever logic is to be invoked in your `if` block should just be invoked in the `returnDatas` function. – David Jan 21 '22 at 14:46

0 Answers0